ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

计算器

2022-05-28 20:31:45  阅读:21  来源: 互联网

标签:num1 num2 int System result 计算器 out


package struct;

import java.util.Scanner;

public class Demo04 {
public static void main(String[] args) {
System.out.println("请输入两个数");
Scanner a = new Scanner(System.in);
int num1 = a.nextInt();
Scanner b = new Scanner(System.in);
int num2 = b.nextInt();
Scanner sc = new Scanner(System.in);
System.out.println("请输入运算符");
String s = sc.nextLine();
switch (s){
case "+":
int sum = sum(num1, num2);
System.out.println("两者的和为:"+sum);
break;
case "-":
int jian = jian(num1, num2);
System.out.println("两者的差为:"+jian);
break;
case "*":
int cheng = cheng(num1, num2);
System.out.println("两者的成为:"+cheng);
break;
case "/":
int chu = chu(num1, num2);
System.out.println("两者的除为:"+chu);
break;
default:
System.out.println("输出错误");
}
a.close();
b.close();
sc.close();

}
public static int sum (int num1,int num2){
int result = 0;
result = num1+num2;
return result;
}

public static int jian (int num1,int num2){
int result = 0;
result = num1-num2;
return result;
}

public static int cheng (int num1,int num2){
int result = 0;
result = num1*num2;
return result;
}

public static int chu (int num1,int num2){
int result = 0;
result = num1/num2;
return result;
}
}

 

 



标签:num1,num2,int,System,result,计算器,out
来源: https://www.cnblogs.com/qingjunSong/p/16321814.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有