In: Computer Science
please make a program by DrRacker
Suppose that we wish to add a new kind of expression known as a case of expression, which acts like a kind of switch-case or if-else-if conditional with multiple outcomes. An example of a case-of expression is: case f x of 0 -> 1; 1 -> 3; 2 -> 5; 3 -> 7; --> 0 The value of the above expression is 0 when the function's return value is none of 0, 1, 2, or 3.
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int x= sc.nextInt();
switch(x)
{
case 0: System.out.println("1");
break;
case 1: System.out.println("3");
break;
case 2: System.out.println("5");
break;
case 3: System.out.println("5");
break;
default: System.out.println("0");
break;
}
}
}