diff --git "a/04 \345\217\266\346\246\225\351\224\213/20230320java\345\237\272\347\241\200.md" "b/04 \345\217\266\346\246\225\351\224\213/20230320java\345\237\272\347\241\200.md" new file mode 100644 index 0000000000000000000000000000000000000000..3b0729703bbe96d6ca76d201ecfd224fc6482ffc --- /dev/null +++ "b/04 \345\217\266\346\246\225\351\224\213/20230320java\345\237\272\347\241\200.md" @@ -0,0 +1,279 @@ +# 巩固题 + +## 1、输出你最想说的一句话! + +* 编写步骤: + +1. 定义类 Homework1 +2. 定义 main方法 +3. 控制台输出5行字符串类型常量值 + +## 2、按步骤编写代码,效果如图所示: + +* 编写步骤: + +1. 定义类 Homework2 + +2. 定义 main方法 + +3. 控制台输出5行字符串类型常量值 + +4. 控制台输出5行字符类型常量值 + + ```JAVA + public class Homework2 { + public static void main(String[] args) { + System.out.println("善学如春起之苗"); + System.out.println("不见其增,日有所长"); + System.out.println("假学如磨刀之石"); + System.out.println("不见其损,年有所亏"); + System.out.println("加油吧!少年"); + System.out.println("J"); + System.out.println("A"); + System.out.println("V"); + System.out.println("A"); + System.out.println("!"); + + } + } + ``` + + + + + +## 3、按步骤编写代码,效果如图所示: + +- 编写步骤: + + 1. 定义类 Homework3 + + 2. 定义 main方法 + + 3. 控制台输出所有布尔类型常量值 + + ```java + public class Homework3 { + public static void main(String[] args) { + boolean nan = true; + System.out.println(nan); + boolean nv = false; + System.out.println(nv); + } + } + ``` + + + +## 4、按步骤编写代码,效果如图所示: + +- 编写步骤: + + 1. 定义类 Homework4 + + 2. 定义 main方法 + + 3. 定义2个 byte类型变量,分别赋byte类型范围内最大值和最小值,并输出在控制台. + + 4. 定义2个 short类型变量,分别赋short类型范围内的值,并输出在控制台. + + 5. 定义2个 int类型变量,分别赋int类型范围内的值,并输出在控制台. + + 6. 定义2个 long类型变量,分别赋超过int类型范围的值,并输出在控制台. + + ```JAVA + public class Homework4 { + public static void main(String[] args) { + System.out.println(Byte.MAX_VALUE);; + System.out.println(Byte.MIN_VALUE); + System.out.println(Short.MAX_VALUE);; + System.out.println(Short.MIN_VALUE); + System.out.println(Integer.MAX_VALUE); + System.out.println(Integer.MIN_VALUE); + long n =(long)(Integer.MAX_VALUE+1l); + long m =(long)(Integer.MIN_VALUE-1l); + System.out.println(n);; + System.out.println(m); + } + } + ``` + + + +## 5、按步骤编写代码,效果如图所示: + + + +* 编写步骤: + 1. 定义类Homework5 + + 2. 定义 main方法 + + 3. 定义2个 float类型变量,分别赋值,并输出在控制台. + + 4. 定义2个 double类型变量,分别赋值,并输出在控制台. + + ```java + public class Homework5 { + public static void main(String[] args) { + float zhiy = -3.14f; + float zhie = 3.14f; + double shu = 3.14; + double shuz = -3.14; + System.out.println(zhiy); + System.out.println(zhie); + System.out.println(shu); + System.out.println(shuz); + } + } + ``` + + + +## 6、交换两个变量的值 + +编写步骤: + +1. 定义类Homework6 +2. 定义 main方法 +3. 定义两个整数变量a,b并赋值 +4. 控制台输出变量a,b互换前的值 +5. 定义一个第三方变量temp +6. 利用第三方变量temp使a,b的值互换 +7. 控制台输出变量a,b互换后的值 + +```java + public static void main(String[] args) { + int a=10; + int b=20; + System.out.println(a); + System.out.println(b); + int temp ; + temp=a; + a=b; + b=temp; + System.out.println(a); + System.out.println(b); + + } +} + +``` + + + +## 7、按步骤编写代码,效果如图所示: + + + +* 开发提示:四则运算的符号 + + ```java + 加: + + 减: - + 乘: * + 除: / + ``` + +* 编写步骤: + + 1. 定义类 Homework7 + + 2. 定义 main方法 + + 3. 定义2个int类型变量x、y,x赋值为100,y赋值为200 + + 4. 定义新变量add,保存变量x,y的和并打印到控制台 + + 5. 定义新变量sub,保存变量x,y的差并打印到控制台 + + 6. 定义新变量mul,保存变量x,y的积并打印到控制台 + + 7. 定义新变量div,保存变量x,y的商并打印到控制台 + + ```java + public class Homework7 { + public static void main(String[] args) { + int x=100; + int y=200; + int add=x+y; + int sub=x-y; + int mul=x*y; + int div=x/y; + System.out.println(add); + System.out.println(sub); + System.out.println(mul); + System.out.println(div); + } + } + ``` + + + +## 8、按步骤编写代码,效果如图所示: + +- 开发提示:四则运算的符号 + + ```java + 加: + + 减: - + 乘: * + 除: / + ``` + +- 编写步骤: + + 1. 定义类 Homework8 + + 2. 定义 main方法 + + 3. 定义2个double类型变量x、y,x赋值为100.8,y赋值为20.6 + + 4. 定义新变量add,保存变量x,y的和并打印到控制台 + + 5. 定义新变量sub,保存变量x,y的差并打印到控制台 + + 6. 定义新变量mul,保存变量x,y的积并打印到控制台 + + 7. 定义新变量div,保存变量x,y的商并打印到控制台 + + ```java + public class Homework8 { + public static void main(String[] args) { + double x=100.8; + double y=20.6; + double add=x+y; + double sub=x-y; + double mul=x*y; + double div=x/y; + System.out.println(add); + System.out.println(sub); + System.out.println(mul); + System.out.println(div); + } + } + ``` + + + +## 9、简答题 + +(1)Java的基本数据类型有哪些?String是基本数据类型吗? + +```java +Java的基本数据类型有:byte,short,int,long,float,double,char,boolean + String不是基本数据类型 +``` + +(2)float f=3.4;是否正确,表达式15/2*2的值是多少 + +```java +float f=3.4; //错误,因为3.4默认是double类型 + System.out.println(15/2*2); //14,因为15/2结果是7 +``` + +(3)char型变量中是否可以存储一个汉字? + +``` +可以 +``` \ No newline at end of file