用java语言编写一个计算器的程序? 5
3个回答
展开全部
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("*****************简易计算器****************");
System.out.println("*\t\t\t\t\t*");
System.out.println("* 使用说明: 1.加法 2.减法 3.乘法 4.除法 *");
System.out.println("*\t\t\t\t\t*");
System.out.println("*****************************************");
for(int i=0;i<100;i++){
System.out.print("\n请选择运算规则:");
int num = input.nextInt();
switch(num){
case 1:
System.out.println("\n******你选择了加法******\n");
System.out.print("请输入第1个加数:");
int jiashu1 = input.nextInt();
System.out.print("请输入第2个加数:");
int jiashu2 = input.nextInt();
System.out.println("运算结果为:" + jiashu1 + " + " + jiashu1 + " = " + (jiashu1 + jiashu2));
break;
case 2:
System.out.println("\n******你选择了减法******\n");
System.out.print("请输入被减数:");
int jianshu1 = input.nextInt();
System.out.print("请输入减数:");
int jianshu2 = input.nextInt();
System.out.println("运算结果为:" + jianshu1 + " - " + jianshu2 + " = " + (jianshu1 - jianshu2));
break;
case 3:
System.out.println("\n******你选择了乘法******\n");
System.out.print("请输入第1个因数:");
int chengfa1 = input.nextInt();
System.out.print("请输入第2个因数:");
int chengfa2 = input.nextInt();
System.out.println("运算结果为:" + chengfa1 + " * " + chengfa2 + " = " + (chengfa1 * chengfa2));
break;
case 4:
System.out.println("\n******你选择了除法******\n");
System.out.print("请输入被除数:");
double chufa1 = input.nextInt();
System.out.print("请输入除数:");
double chufa2 = input.nextInt();
System.out.println("运算结果为:" + chufa1 + " / " + chufa2 + " = " + (chufa1 / chufa2) + " 余 " + (chufa1 % chufa2));
break;
default:
System.out.println("\n你的选择有错,请重新选择!");
break;
}
}
}
}
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("*****************简易计算器****************");
System.out.println("*\t\t\t\t\t*");
System.out.println("* 使用说明: 1.加法 2.减法 3.乘法 4.除法 *");
System.out.println("*\t\t\t\t\t*");
System.out.println("*****************************************");
for(int i=0;i<100;i++){
System.out.print("\n请选择运算规则:");
int num = input.nextInt();
switch(num){
case 1:
System.out.println("\n******你选择了加法******\n");
System.out.print("请输入第1个加数:");
int jiashu1 = input.nextInt();
System.out.print("请输入第2个加数:");
int jiashu2 = input.nextInt();
System.out.println("运算结果为:" + jiashu1 + " + " + jiashu1 + " = " + (jiashu1 + jiashu2));
break;
case 2:
System.out.println("\n******你选择了减法******\n");
System.out.print("请输入被减数:");
int jianshu1 = input.nextInt();
System.out.print("请输入减数:");
int jianshu2 = input.nextInt();
System.out.println("运算结果为:" + jianshu1 + " - " + jianshu2 + " = " + (jianshu1 - jianshu2));
break;
case 3:
System.out.println("\n******你选择了乘法******\n");
System.out.print("请输入第1个因数:");
int chengfa1 = input.nextInt();
System.out.print("请输入第2个因数:");
int chengfa2 = input.nextInt();
System.out.println("运算结果为:" + chengfa1 + " * " + chengfa2 + " = " + (chengfa1 * chengfa2));
break;
case 4:
System.out.println("\n******你选择了除法******\n");
System.out.print("请输入被除数:");
double chufa1 = input.nextInt();
System.out.print("请输入除数:");
double chufa2 = input.nextInt();
System.out.println("运算结果为:" + chufa1 + " / " + chufa2 + " = " + (chufa1 / chufa2) + " 余 " + (chufa1 % chufa2));
break;
default:
System.out.println("\n你的选择有错,请重新选择!");
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询