java - break to lable as default case in switch statment not behaving logically -


Thank you for reading first. Apart from this, I am very aware of how I can do it, the way I want it, I am just experimenting and not getting the expected result. When I run this code, I hope that when I enter the letter X, I will be asked to try again and try again to write again. Well, I am. However, the program will break to start: based on the new value of the label and the process we found in the default case. If I enter the letter B on my second attempt, nothing in the switch statement is executed. If you enter letter B in your second attempt, the program will print that you have entered B and then the program will terminate. Why is it like this?

  import java.util.Scanner; Public class support {public static zero main (string [] args) {scanner KB = new scanner (System.in); System.out.println ("Enter the letter B:"); Char input = kb.nextLine (). Fourat (0); Start: Switch (Input) {case 'B': System.out.println ("Good job!"); break; Default: System.out.println ("Try again:"); Input = kb.nextLine (). Fourat (0); Println (input); Break start; } <}>  

label is for the statement break The termination loop or switch statement that is labeled with the related label transfers control back to the not label your switch < / Code> statement is only falling until the end of the program, as it should be.

The label break was nested

for more information, see.

/ html>

Comments