So I have a string Streams in a class
and a method which requires user to enter either 1,2,3
if they enter 1 Streams=Science, if they enter 2 Streams=2, If they enter 3 Stream= what ever the user inputs. The logic is fairly simple but I can't get it to work
here is the code demo
alsoScanner input = new Scanner(System.in); String Streams; public void InputStream() { System.out.println("Enter the Stream."); System.out.println("1 for Science, 2 for Arts, 3 for others"); int answer=input.nextInt(); if (answer==1) { Streams="Science"; } if(answer==2) { Streams="Arts"; } else { System.out.println("enter the subject"); input.reset(); Streams=input.nextLine(); } } //i am gonna call the constructor "method" public method(){ InputStream(); System.out.println(Streams);
in output console the text from the 3rd if statement"enter the subject" appears every single time even when the user enters 1 or 2.
A quick reply will be really appreciated
}