package com.lime.method; import java.util.Scanner; public class Demo06 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("输入:"); if (scanner.hasNextInt()){ int i=scanner.nextInt(); String a = scanner.next(); int j=scanner.nextInt(); switch (a){ case"+": int add=add(i,j); System.out.println(add); break; case"-": int jian=jian(i,j); System.out.println(jian); break; case"*": int cheng=cheng(i,j); System.out.println(cheng); break; case"/": int chu=chu(i,j); System.out.println(chu); break; } scanner.close(); } } public static int add(int a,int b){ return a+b; } public static int jian(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){ if(b==0){ System.out.println("错误"); } return a/b; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)