I am actually having trouble with my program. Actually I study in school (11 grade- junior college) so please explain me in very simple language. I am developing a quiz, very basic school project and so the programs goes on like this.... I want the user to enter his/her choice, by inputting numbers from 1-4. I don't want the user to enter an alphabet, letter or special character or any other no. other than 1-4. I tried using try and catch but my program stops after throwing the exception. I want the program code to run even after displaying the error message System.out.println(" Invalid input. Please enter a number between 1-4"); sample program
import java.io.*;
import java.lang;
public class
{
public static void main()throws IOException
{
InputStreamReader read =new InputStreamReader (System.in);
BufferedReader in =new BufferedReader (read);
System.out.println(" Select your category");
System.out.println(" 1. Food");
System.out.println(" 2. National");
System.out.println("");
System.out.println(" Enter your choice");
int choice=Integer.parseInt(in.readLine());
if(choice==1)//food category
{
int score = 0;
System.out.println("what are dynamites made?");
System.out.println("1. peanuts");System.out.println("2. grapes");
System.out.println("3. flaxseeds");System.out.println("4. fish");
System.out.println(" Enter your choice");
int food1= Integer.parseInt(in.readline());
if(c1=1)
{ System.out.println(" Correct answer");
score=score+10
}
else
{
System.out.println(" Wronge answer");
score=score+0
}
//then i have the second question with the same format
}
if(choice==2)//natioanl category with the same format as above
{//two question with if else statements in them }
}
}// also help me where to add the try and catch statements