import java.util.Scanner;
public class yunsuan {
static Scanner sc = new Scanner(System.in);//全局变量
static int first = 0;
static int second = 0;
static int choice = 0;
public static void main(String[] args) {
show();
inputFirst();
inputSecond();
System.out.println(run());
}
/**
* 显示计算器屏幕,选择运算
*
* @return
*/
public static void show() {
System.out.println("1.+\t2.-");
System.out.println("3.x\t4.÷");
System.out.println("5.pow");
System.out.print("请选择运算: ");
choice = Integer.parseInt(sc.nextLine());
}
/**
* 输入第一个数
*/
public static void inputFirst() {
System.out.print("请输入第一个数:");
first = Integer.parseInt(sc.nextLine());
}
/**
* 输入第二个数
*/
public static void inputSecond() {
System.out.print("请输入第二个数:");
second = Integer.parseInt(sc.nextLine());
}
/**
* 运算
* @return
*/
public static double run() {
double s = 0.0;
double i = 0.0;
switch (choice) {
case 1:
s = first + second;
break;
case 2:
s = first - second;
break;
case 3:
s = first * second;
break;
case 4:
s = 1.0 * first / second;
break;
case 5:
s = Math.pow(first,second);
i = second*second;
}
return s;
}
}
选择运算并计算
最新推荐文章于 2024-10-06 20:16:20 发布