0

What's wrong here?

import java.util.Scanner; class Demo{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int emotion = scanner.nextInt(); switch (emotion) { case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: System.out.println("Unknown emotion"); } /* 1 - "You are happy!" 2 - "You are sad!" 3 - "You are angry!" 4 - "You are surprised!" other - "Unknown emotion" */ // add switch statement here

13th Jan 2025, 12:15 PM
Umutcan Topuz
Umutcan Topuz - avatar
2 Answers
+ 2
Do you have println with L or with i/I? And you're missing the break for case 2.
13th Jan 2025, 1:27 PM
Ausgrindtube
Ausgrindtube - avatar
0
Umutcan Topuz , > the presented code seems to be truncated: 2 closing curly braces are missing at the end of the code. > it is also a good idea to use some indentation / formatting with the `switch ... case` statement like: ... case 1: System.out.println("You are happy!"); break; case 2: ... this gives a much better readability.
14th Jan 2025, 9:01 PM
Lothar
Lothar - avatar