0
public class Carseat { static int state = 3; static int idle=1; static int belted=2; static int unbelted=3; public static vo
What am I doing wrong here
6 Réponses
+ 6
Hello!
Please share the full code as there's not enough information as of right now to help out with your problem
0
public class Carseat {
static int state = 3;
static int idle=1;
static int belted=2;
static int x= 0;
static int unbelted=3;
public static void main(String[] args) {
if(x>3)
switch(state) {
case 1:
System.out.println("Please turn off the lights");
break;
case 2:
System.out.println("Drive safely ");
break;
case 3:
System.out.println("please buckle up ");
default:
System.out.println("Everything is ok");
}
}
}
0
Hi....the if condition i.e. (if(x > 3)) evaluates to false that is why if body is not getting executed
Change the value of x to something greater that 3
0
Gives two answers first case output and the default case ...
0
Sinthani Ngulube this is because you didn't put break statement for case 3
0
Ooops lemme change that....
It's only printing case 3. I want it to print all of the states.