循环+switch计算器练习
作者:互联网
import java.util.Scanner;
public class Cacula {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//循环用户输入的数据
while(true){
System.out.println("请输入第一个数字:");
int firstnum = scanner.nextInt();
System.out.println("请输入方式");
String metho = scanner.next();
System.out.println("请输入第二个数字");
int secondnum = scanner.nextInt();
switch (metho){
case "+":
System.out.println(firstnum+secondnum);
break;
case "-":
System.out.println(firstnum-secondnum);
break;
case "*":
System.out.println(firstnum*secondnum);
break;
case "/":
System.out.println(firstnum/secondnum);
break;
}
}
}
//加
public static int sum(int i,int j){
return i+j;
}
//减
public static int sub(int i,int j){
return i-j;
}
//乘
public static int mul(int i,int j){
return i*j;
}
//除
public static int div(int i,int j){
return i/j;
}
}
标签:int,练习,System,secondnum,switch,计算器,println,public,out 来源: https://www.cnblogs.com/Susunshome/p/14958304.html