1.导入包;
import java.util.Scanner;
2.实例化Scanner:
Scanner sc = new Scanner(System.in);
3.接收控制台输入的整数
int num = sc.nextInt();
*/
//1.导入包
import java.util.Scanner;
class ScannerDemo
{
public static void main(String[] args)
{
//2.实例化Scanner
Scanner sc = new Scanner(System.in);
do{
System.out.print("请输入第一个数:");
int num = sc.nextInt();
System.out.print("请输入第二个数:");
int num2 = sc.nextInt();
System.out.print("1(加) 2(减) 3(乘) 4(除) :");
int op = sc.nextInt();
int result = 0;
switch (op){
case 1:
result = num + num2;
break;
case 2:
result = num - num2;
break;
case 3:
result = num * num2;
break;
case 4:
result = num / num2;
break;
default:
System.out.println("非法的运算符输入!");
break;
}
System.out.println("结果:" + result);
System.out.print("1(继续) 0(退出)");
int num3 = sc.nextInt();
if(num3 == 0){
System.out.println("谢谢使用!");
break;
}
}while(true);