In the below code when i comment the breaks,when i write a case(say "start") it will print all the cases output below,means all the three lines are printed,when i write "stop" it prints two output "Mechine stopped" and "No command given",why do i need to give break statement as the compiler searches for the cases,if matches then print the related output.
import java.util.Scanner;
public class App{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String text = input.nextLine();
switch(text){
case "start":
System.out.println("Mechine Started");
break;
case "stop":
System.out.println("Mechine stopped");
break;
default:
System.out.println("No command given");
}
}
}