package com.beijing.xiaowen.methods;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
int a = 0;
int b = 0;
String abc = "";
Scanner scanner = new Scanner(System.in);
System.out.println("输入内容:");
if (scanner.hasNextInt()){
a = scanner.nextInt();
}
Scanner scanner1 = new Scanner(System.in);
System.out.println("输入内容:");
if (scanner1.hasNextInt()){
b = scanner1.nextInt();
}
Scanner scanner2 = new Scanner(System.in);
System.out.println("输入内容:");
if (scanner2.hasNextLine()){
abc = scanner2.nextLine();
}
method(a,b,abc);
scanner.close();
}
static void method(int a,int b,String x){
switch (x){
case "+":
System.out.println(a+b);
break;
case "-":
System.out.println(a-b);
break;
case "*":
System.out.println(a*b);
break;
case "/":
System.out.println(a/b);
break;
}
}
}
标签:scanner,Scanner,int,练习,System,计算器,简单,println,out
From: https://www.cnblogs.com/always0708/p/16808357.html