the switch statement | Sololearn: Learn to code for FREE!
0

the switch statement

hello everyone in the community, i'm having a problem doing the java switch statement quick test. this is my code but i only have 3 part of the quiz doing good and i need have all fine for approved // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry"); break; case 4: System.out.println("You are surprised"); break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } }

5th Feb 2021, 8:58 AM
Ricardo Rodriguez
Ricardo Rodriguez - avatar
12 Antworten
- 5
switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: if (!(emotion%4==0)){ System.out.println("You are angry!"); } break; case 4: if (!(emotion%6==0)){ System.out.println("You are surprised!"); } break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } } //this is correct!!
7th Feb 2021, 5:25 AM
Ricardo Rodriguez
Ricardo Rodriguez - avatar
+ 6
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.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are suprised!"); break; default: System.out.println("Unknown emotion."); } // your code goes here } } test case 5 not working
3rd May 2021, 7:42 PM
Chinecherem C Ejikeme
Chinecherem C Ejikeme - avatar
+ 4
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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } } This code is correct
7th May 2022, 6:25 PM
B.P.P.M. Premadase
B.P.P.M. Premadase - avatar
+ 2
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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: System.out.println("Unknown emotion."); } } }
17th Aug 2021, 3:48 PM
Nischal Maharjan
+ 1
import java.util.Scanner; public class Main { 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!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } }
7th Apr 2023, 9:57 AM
Eden Mekonnen
Eden Mekonnen - avatar
0
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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } }
7th May 2022, 6:25 PM
B.P.P.M. Premadase
B.P.P.M. Premadase - avatar
0
switch(emotion){ case 1: System.out.println("You are happy! "); break; case 2: System.out.println("You are sad! "); break; case 3: System.out.println("You are angry! "); break; case 4: System.out.println("You are surprised! "); break; default: System.out.println("Unknown emotion. "); } } }
8th Sep 2022, 1:29 PM
Rosalid Mbuthia
0
Is there anything I miss friends???? 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.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised"); break; default: System.out.println("Unknown emotion."); } } }
13th Oct 2022, 5:58 PM
Ephrem Hailu
Ephrem Hailu - avatar
0
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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: System.out.println("Unknown emotion."); } } } This is a correct code
23rd Dec 2022, 2:24 PM
James Joshua
James Joshua - avatar
0
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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: System.out.println("You are angry!"); break; case 4: System.out.println("You are surprised!"); break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } }
11th Feb 2023, 6:10 PM
Ghulam Qambar Dobal
Ghulam Qambar Dobal - avatar
- 1
can you write the code, because i don't know how to do that ? i mean something like this : 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." */ // your code goes here switch (emotion){ case 1: System.out.println("You are happy!"); break; case 2: System.out.println("You are sad!"); break; case 3: if (!(emotion%4==0)){ System.out.println("You are angry"); } break; case 4: if (!(emotion%6==0)){ System.out.println("You are surprised"); } break; default: if (emotion > 4 || emotion <1 ){ System.out.println("Unknown emotion."); } } } } but the error still remains
5th Feb 2021, 7:15 PM
Ricardo Rodriguez
Ricardo Rodriguez - avatar
- 4
The switch Statement Your robot can recognize your emotions marked with number that represents each of them: 1 - You are happy! 2 - You are sad! 3 - You are angry! 4 - You are surprised! Write a program that takes the emotion number as input and outputs the corresponding message in given format. If the input is an emotion that the program doesnÔÇÖt know, it should output: "Unknown emotion.".
5th Feb 2021, 9:05 AM
Ricardo Rodriguez
Ricardo Rodriguez - avatar