您的位置:首页 > 编程语言 > Java开发

JAVA简易计算器

2020-09-01 23:43 991 查看

JAVA简易计算器

import java.util.Scanner;

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: