JAVA简易计算器
用函数调用方法制作一个简易的计算器
public class Demo7 {
public static void main(String[] args) {
int a=0;
char c=' ';
int b=0;
Scanner scanner = new Scanner(System.in);
a=scanner.nextInt();
c=scanner.next().charAt(0);
b=scanner.nextInt();
switch (c){
case '+':
System.out.println("和为:"+add(a,b));
break;
case '-':
System.out.println("差为:"+jian(a,b));
break;
case '*':
System.out.println("积为:"+cheng(a,b));
break;
case '/':
System.out.println("商为:"+chu(a,b));
break;
}
}
public static int add(int a,int b){
int c= a+b;
return c;
}
public static int jian(int a,int b){
int c= a-b;
return c;
}
public static int cheng(int a,int b){
int c= a*b;
return c;
}
public static int chu(int a,int b){
int c= a/b;
return c;
}
}