2021-09-11

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.”.

Sample input
1

Sample output
You are happy!

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."
       */
       
       // 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.");
		}
       
   }
}

上一篇:Linux学习记录四——操作文件与目录


下一篇:【剑指offer】替换空格,请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。