package com.zhang.method; import java.util.Scanner; public class Demo07 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("请输入一个数:"); int num1=scanner.nextInt(); Scanner scanner1=new Scanner(System.in); System.out.println("请输入你要进行的操作(+,-,*,/):"); String ope=scanner1.nextLine(); Scanner scanner2=new Scanner(System.in); System.out.println("请再输入一个数:"); int num2=scanner2.nextInt(); int i=0; System.out.println("输出的结果为:"); switch(ope){ case "+":i=add(num1,num2); System.out.println(num1+"+"+num2+"="+i); break; case "-":i=dec(num1,num2); System.out.println(num1+"-"+num2+"="+i); break; case "*":i=cheng(num1,num2); System.out.println(num1+"*"+num2+"="+i); break; case "/":i=chu(num1,num2); System.out.println(num1+"/"+num2+"="+i); break; } } public static int add(int a,int b){ return a+b;} public static int dec(int a,int b){ return a-b; } public static int cheng(int a,int b){ return a*b; } public static int chu(int a,int b){ return a/b; } }
07-05
817
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)