1 package a.b;數組
2 app
3 public class test ide
4 {學習
5 it
6 static void BasicVariables()class
7 {test
8 //1、變量的類型的學習變量
9 System.out.println("1、變量的類型的學習 ");float
10 static
11 // byte 表數範圍:-128~127, 存儲大小佔1byte
12 byte a;
13 a = 12;
14 System.out.println("byte num Is " + a);
15
16 // int 佔4字節
17 int b;
18 b = 66633;
19 System.out.println("int num Is " + b);
20
21 // short 佔2字節
22 short c;
23 c = 1234;
24 System.out.println("short num Is " + c);
25
26 // long 佔2字節
27 long d;
28 d = 655366;
29 System.out.println("long num Is " + d);
30
31 float e;
32 e = (float)12.6;
33 System.out.println("fload num Is " + e);
34
35 // int 佔4字節
36 double f;
37 f = 33.4;
38 System.out.println("double num Is " +f);
39
40 // short 佔2字節
41 char g;
42 g = 'a';
43 System.out.println("char num Is " + g);
44
45 // long 佔2字節
46 boolean h;
47 h = true;
48 System.out.println("boolean num Is " + h);
49 }
50
51 static void AboutArrays()
52 {
53 // 2、 數組的學習
54 System.out.println("2、 數組的學習 ");
55
56
57 // 基本類型數組賦值、輸出
58 int []a ;
59 a = new int [5];
60
61 a[0] = a[1] = a[2] = a[3] = a[4] = 9;
62
63 for (int i = 0; i < 5; i++)
64 {
65 System.out.println(a[i]);
66 }
67
68 // 基本類型數組賦值、輸出
69 int []b = new int [5];
70
71 for (int i = 0; i < 5; i++)
72 {
73 b[i] = a[i] + i +1;
74 System.out.println(b[i]);
75 }
76
77 // 基本類型數組初始化時候賦值
78 int []c = new int [] {3,4,5,6,7};
79
80 for (int i = 0; i < 5; i++)
81 {
82 System.out.println(c[i]);
83 }
84
85 // 字符數組
86 String []d = new String [] {"you","are","my","small","apple"};
87
88 for (int i = 0; i < 5; i++)
89 {
90 System.out.println(d[i]);
91 }
92 }
93
94 public static void main(String[] args)
95 {
96 //1、基本變量
97 BasicVariables();
98
99 //2、數組
100 AboutArrays();
101 }
102
103
104
105 }