+ 1

What is wrong in this code?

Why not compillating this code?? Anyone know? Это задача про эмоции робота Для изучения switch и case Вот я списал с правильного ответа этот код, но он не проходит import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int emotion = scanner.nextInt(); /* 1 - "You are happy!" 2 - "You are sad!" 3 - "You are angry!" 4 - "You are surprised!" other - "Unknown emotion." */ switch(emotion){ case 1: System.out.print("You are happy!"); break; case 2: System.out.print("You are sad!"); break; case 3: System.out.print("You are angry!"); break; case 4: System.out.print("You are surprised!"); default: System.out.print("Unknown emotion."); } } }

20th Aug 2022, 10:14 AM
T Akvinski
T Akvinski - avatar
3 Respuestas
+ 2
The code works tho. You forgot to write a break at 4th case
20th Aug 2022, 10:27 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 2
T Akvinski break; is missing in case 4 and no need to create another question. You can wait for reply https://www.sololearn.com/Discuss/3074997/?ref=app
20th Aug 2022, 10:29 AM
A͢J
A͢J - avatar
+ 1
Very Thx guys, you super! I'm bit stupid
20th Aug 2022, 10:49 AM
T Akvinski
T Akvinski - avatar