0
Who can help me? Java question
I donât understand very well Java so far. Who could help me explaining this short codeâs lines. ââ No entiendo aĂșn mucho Java. Quien podrĂa explicarme este cĂłdigo de Java đ€đ int x=1; Switch(1){ Case 1: System.out.print(1); Case 2: System.out.print(2); break; Case 3: System.out.print(3); } No entiendo porque la respuesta es 12 Gracias a quien me pueda explicar đđđ
5 Answers
+ 5
In your program errors are there ..every java keyword starts with lowercase letters..in your code you wrote Switch,Case ...(there must be in lowercase)
Coming to your program logic....
variable x is initialized with value 1.
In switch ,it searches is there any matching case label available or not.if available then it executes all matching case labels.. otherwise not execute.
Here, switch(1) contains value 1 so,corresponding case 1 is executed and then there is no break statement so it execute case 2 too .
Now , output is
1
2
NOTE: one thing int x=1 here there is no use
+ 3
anyone who has knowledge about Java
have you learnd c
switch has condition
cases have answers
if any one of following cases will satisfy the condition it breaks the program or stop the program
cases = options
break = stop the process when this satisfy
+ 2
Johanna Andrade
My pleasure...đ
+ 1
Thanks âNavyađ„ for your explanation đ
+ 1
thanks Deepak Jaiswar âșïž