I am taking input for my application using scanner. My code is as follows:
Scanner sc = new Scanner(System.in);
System.out.println("Do you want to give user input :YES/NO")
if(sc.next().equals("YES")){
System.out.println("which input? student or teacher name")
if(sc.next().equals("student")){
system.out.println("do something");
}
if(sc.next().equals("teacher")){
system.out.println("do something");
}
}
}else
{
system.out.println("program will run itseld");
}
Code is working fine but it is asking input twice. Suppose if I enter student it will not proceed but when I enter student again second time my program starts working. I also saw some similar questions on stackoverflow and tried their solutions but I am not able to resolve this. Please help.