【Java 基础篇】【第三课】表达式、控制结构
2017-09-28 17:32
183 查看
1 package a.b;
2
3 public class test
4 {
5
6 static void BasicVariables()
7 {
8 //一、变量的类型的学习
9 System.out.println("一、变量的类型的学习 ");
10
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 // 二、 数组的学习
54 System.out.println("二、 数组的学习 ");
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 //一、基本变量
97 BasicVariables();
98
99 //二、数组
100 AboutArrays();
101 }
102
103
104
105 }
2
3 public class test
4 {
5
6 static void BasicVariables()
7 {
8 //一、变量的类型的学习
9 System.out.println("一、变量的类型的学习 ");
10
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 // 二、 数组的学习
54 System.out.println("二、 数组的学习 ");
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 //一、基本变量
97 BasicVariables();
98
99 //二、数组
100 AboutArrays();
101 }
102
103
104
105 }
相关文章推荐
- 【Java 基础篇】【第三课】表达式、控制结构
- 【Java 基础篇】【第三课】表达式、控制结构
- 【Java 基础篇】【第三课】表达式、控制结构
- JAVA入门.零基础学Java语言 MOOC 第二 第三 第四周 比较 判断 分支 循环 —————— 程序控制结构(顺序,分支,循环)
- 黑马程序员—【Java基础篇】之正则表达式
- java控制循环结构day_5
- 《黑马程序员》 java基础巩固之流程控制中的循环结构
- Java流程控制之选择结构
- Java基础篇笔记(二) ---容易忽视的表达式结果的类型,求概率、几率问题
- Java复习笔记+经验总结-01 运算符 表达式 数组 流程控制语句
- Java心得---表达式、流程控制
- JAVA流程控制循环结构(while和do{}while()循环结构)
- Java基础循环结构,以及循环控制语句break,continue,return
- 01_Java语言基础部分(数据类型与表达式、流程控制语句、数组与方法)
- Java程序流程控制:判断结构、选择结构、循环结构
- Java表达式、流控制、数组、字符串和类、对象、包、接口——Java学习笔记(三)
- Java心得---表达式、流程控制
- 数据结构之应用 "栈(Stack)" 实现: 解析算术表达式及计算求值 (C#/Java)
- JavaScript基础语法:数据类型、变量、控制结构、函数、表达式
- C++---基础篇(运算符/表达式/控制语句)