1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package 本章总结;
public class A01class {
public int ope( int Operator, int num1, int num2) {
switch (Operator) {
case 1 :
num1 += num2;
break ;
case 2 :
num1 -= num2;
break ;
case 3 :
num1 *= num2;
break ;
case 4 :
num1 /= num2;
break ;
default :
System.out.println( "输入有误!重新输入:" );
A01 A = new A01();
A.main( null );
break ;
}
System.out.println( "运算结果:" + num1);
return num1;
}
} package 本章总结;
import java.util.Scanner;
public class A01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
A01class A01 = new A01class();
Scanner in = new Scanner(System.in);
System.out.print( "请选择运算: 1.加法 2.减法 3.乘法 4.除法:" );
int Operator = in.nextInt();
System.out.print( "请输入第一个数:" );
int num1 = in.nextInt();
System.out.print( "请输入第二个数:" );
int num2 = in.nextInt();
A01.ope(Operator, num1, num2);
}
} |
本文转自 Y幕徐 51CTO博客,原文链接:http://blog.51cto.com/765133133/1426619