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

20th Oct 2019, 1:03 PM
Sinthani Ngulube
6 ответов
+ 6
Hello! Please share the full code as there's not enough information as of right now to help out with your problem
20th Oct 2019, 1:15 PM
Faisal
Faisal - avatar
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"); } } }
20th Oct 2019, 1:19 PM
Sinthani Ngulube
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
20th Oct 2019, 1:30 PM
Rishi Anand
Rishi Anand - avatar
0
Gives two answers first case output and the default case ...
20th Oct 2019, 1:45 PM
Sinthani Ngulube
0
Sinthani Ngulube this is because you didn't put break statement for case 3
20th Oct 2019, 1:48 PM
Rishi Anand
Rishi Anand - avatar
0
Ooops lemme change that.... It's only printing case 3. I want it to print all of the states.
20th Oct 2019, 1:52 PM
Sinthani Ngulube