public class TestArgs{
public static void main(String[] args){
if(args.length<3){
System.out.println("usage java TestArgs \"n1\" \"op\"\"n2\"");
System.exit(-1);
}
double d1 = Double.parseDouble(args[0]);
double d2 = Double.parseDouble(args[2]);
double d = 0;
if(args[1].equals("+"))d = d1+d2;
else if(args[1].equals("-"))d = d1-d2;
else if(args[1].equals("x"))d = d1*d2;
else if(args[1].equals("/"))d = d1/d2;
else {
System.out.println("error");
System.exit(0);
}
System.out.println(d);
}
}
Array name = new array element type [array length];
The array size cannot be defined during initialization.
At the beginning, I was learning Java, and now I am learning videos step by step. I feel that I may have to review my history in the future. So I will record what I have done today. In this way, you may be able to review the knowledge points later. 2011-11-15 14:08:15
Watch the video of Shang xuetang
Paste the code. The original video only chooses to sort and adds a bubble sort.
View code
1 public class testselectionsort {
2 public static void main (string [] ARGs ){
3 int [] A = new int [args. Length];
4 For (INT I = 0; I <args. length; I ++ ){
5 A [I] = integer. parseint (ARGs [I]);
6}
7
8 testselectionsort. Print ();
9 bubblesort ();
10 testselectionsort. Print ();
11
12}
13
14 Private Static void print (INT [] ){
15 For (INT I = 0; I <A. length; I ++ ){
16 system. Out. Print (A [I]);
17}
18 system. Out. println ();
19}
20 // sort by selection
21 Private Static void selectsort (INT [] ){
22 For (INT I = 0; I <A. length; I ++ ){
23 For (Int J = I + 1; j <A. length; j ++ ){
24 if (a [I]> A [J]) {
25 int temp;
26 temp = A [I];
27 A [I] = A [J];
28 A [J] = temp;
29}
30}
31}
32}
33 // sort by bubble
34 Private Static void bubblesort (INT [] ){
35 For (INT I = 0; I <A. Length-1; I ++ ){
36 For (Int J = 0; j <A. length-i-1; j ++ ){
37 if (a [J + 1] <A [J]) {
38 int temp = 0;
39 temp = A [J];
40 A [J] = A [J + 1];
41 A [J + 1] = temp;
42}
43}
44}
45}
46}