import java.util.Scanner;
public class Demo06 {
public static void add() {
Scanner scanner =new Scanner(System.in);
int x=scanner.nextInt();
int y=scanner.nextInt();
int result=x+y;
System.out.println(result);
}
public static void minus() {
Scanner scanner =new Scanner(System.in);
int x=scanner.nextInt();
int y=scanner.nextInt();
int result=x-y;
System.out.println(result);
}
public static void mul() {
Scanner scanner =new Scanner(System.in);
int x=scanner.nextInt();
int y=scanner.nextInt();
int result=x*y;
System.out.println(result);
}
public static void div() {
Scanner scanner =new Scanner(System.in);
int x=scanner.nextInt();
int y=scanner.nextInt();
int result=x/y;
System.out.println(result);
}
public static void main(String[] args) {
int m;
do {
System.out.println("1.加法运算");
System.out.println("2.减法运算");
System.out.println("3.乘法运算");
System.out.println("4.除法运算");
System.out.println("=======================");
System.out.println("选择运算功能的序号:");
Scanner scanner=new Scanner(System.in);
int x=scanner.nextInt();
switch (x){
case 1:
System.out.println("输入两个数:");
add();//选1的时候调用add()方法
break;
case 2:
System.out.println("输入两个数:");
minus();//选2的时候调用minus()方法
break;
case 3:
System.out.println("输入两个数:");
mul();//选3的时候调用mul()方法
break;
case 4:
System.out.println("输入两个数:");
div();//选4的时候调用div()方法
break;}
System.out.println("是否继续,继续输入1,否则输入0");
m=scanner.nextInt();
} while (m==1);
}
}
看了狂神的b站教学,试着自己写了一个程序,借鉴了这篇文章
代码还有很多不足,希望大神指正。