SwitchStatement.java
The switch statement in java, and how to input an int variable and a char variable int java.
import java.util.Scanner; // to make it available to input
public class SwitchStatement {
public static void main(String args[]) {
int x = 6, y = 9;
char op = '+';
Scanner sc = new Scanner(System.in);
x = sc.nextInt(); // input statement in java
y = sc.nextInt();
op = sc.next().charAt(0); // input a character
switch(op) {
case '+' :
System.out.println(x + y);
break;
case '-' :
System.out.println(x - y);
break;
case '*' :
System.out.println(x * y);
break;
case '/' :
System.out.println(x / y);
break;
default :
System.out.println("没有找到合适的操作符");
}
}
}