2023.7.14
1 2023.7.14 周五 2 //递归:适用于基数bi'ji 3 public class test 4 { 5 public static void main(String[] args) 6 { 7 8 System.out.println(f(5)); 9 } 10 public static int f(int n) 11 { 12 if(n == 1) 13 { 14 return 1; 15 } 16 else 17 { 18 return n*f(n-1); 19 } 20 } 21 } 22 import java.util.Scanner; 23 //简单计算器(加减乘除) 24 public class test { 25 public static void main(String[] args) 26 { 27 double a = 0.0; 28 double b = 0.0; 29 double ret = 0.0; 30 Scanner scanner = new Scanner(System.in); 31 System.out.println("请输入第一个数:"); 32 a = scanner.nextDouble(); 33 System.out.println("请输入运算符:"); 34 String c = scanner.next(); 35 System.out.println("请输入第二个数:"); 36 b = scanner.nextDouble(); 37 switch(c) 38 { 39 case "+": 40 ret = jia(a,b); 41 System.out.println(a+"+"+b+"="+ret); 42 break; 43 case "-": 44 ret = jian(a,b); 45 System.out.println(a+"-"+b+"="+ret); 46 break; 47 case "*": 48 ret = cheng(a,b); 49 System.out.println(a+"*"+b+"="+ret); 50 break; 51 case "/": 52 ret = chu(a,b); 53 System.out.println(a+"/"+b+"="+ret); 54 break; 55 default: 56 System.out.println("输入有误"); 57 break; 58 } 59 scanner.close(); 60 } 61 public static double jia(double m,double n) 62 { 63 return m+n; 64 } 65 public static double jian(double m,double n) 66 { 67 return m-n; 68 } 69 public static double cheng(double m,double n) 70 { 71 return m*n; 72 } 73 public static double chu(double m,double n) 74 { 75 return m/n; 76 } 77 }