What's causing the error message for the InputMismatchEx ception in this code to loop?
import java.io.*;
import java.util.*;
public class clubreg
{
public static void main(String args[])throws IOException
{
System.out.prin t("\t\t\t\t\t\t \tClub Registration Project by Andrea Sanchez,Aaron Go,Lycon Soliba and Patrick Balisong!\n");
BufferedReader x=new BufferedReader( new InputStreamRead er(System.in));
Scanner y=new Scanner(System. in);
String name, curr, section, exco, sure ,rusure, tryagain;
int yrlvl=0, index=0,control =0, length,same=1,n osame=0;
char csure='y',ctrya gain='y',ccurr, csection,cexco, crusure='n';
boolean a=true;
while(ctryagain =='y')
{
System.out.prin tln("What is your name?");
name=x.readLine ();
System.out.prin tln("What is your year level?\n\t1 for 1st year\n\t2 for 2nd year\n\t3 for 3rd year\n\t4 for 4th year");
while(a==true)
{
try
{
yrlvl=y.nextInt ();
a=false;
}
catch(InputMism atchException e)
{
System.err.prin tln("Error! Input numbers only!Enter another number");
}
}
a=true;
while(yrlvl>4|| yrlvl<1)
{
System.out.prin tln("Error! Choose from 1-4 only!");
yrlvl=y.nextInt ();
}
...
I'm losing my mind... Please Help me.
import java.io.*;
import java.util.*;
public class clubreg
{
public static void main(String args[])throws IOException
{
System.out.prin t("\t\t\t\t\t\t \tClub Registration Project by Andrea Sanchez,Aaron Go,Lycon Soliba and Patrick Balisong!\n");
BufferedReader x=new BufferedReader( new InputStreamRead er(System.in));
Scanner y=new Scanner(System. in);
String name, curr, section, exco, sure ,rusure, tryagain;
int yrlvl=0, index=0,control =0, length,same=1,n osame=0;
char csure='y',ctrya gain='y',ccurr, csection,cexco, crusure='n';
boolean a=true;
while(ctryagain =='y')
{
System.out.prin tln("What is your name?");
name=x.readLine ();
System.out.prin tln("What is your year level?\n\t1 for 1st year\n\t2 for 2nd year\n\t3 for 3rd year\n\t4 for 4th year");
while(a==true)
{
try
{
yrlvl=y.nextInt ();
a=false;
}
catch(InputMism atchException e)
{
System.err.prin tln("Error! Input numbers only!Enter another number");
}
}
a=true;
while(yrlvl>4|| yrlvl<1)
{
System.out.prin tln("Error! Choose from 1-4 only!");
yrlvl=y.nextInt ();
}
...
I'm losing my mind... Please Help me.
Comment