20165324 "Java Program design" The 2nd week study Summary textbook Learning content Summary
Here's what to learn this week:
- Basic data types
- Integer type: Byte,shout,int,long.
- Character type: char.
- Floating-point type: float,double.
- Boolean type: Boolean.
- Input and output
- The use of scanner must first be imported into the Scanner class: The
import java.util.Scanner; next step is to create a scanner object: Scanner sc = new Scanner(System.in); Finally, reading data from the keyboard is saved to the variable: int i=sc.nextInt(); double dd=sc.nextDouble(); String s=sc.next(); Note that you cannot get a character directly from the keyboard. Baidu to:
//打印一个从键盘输入的字符import java.util.Scanner;public class Zifu{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); System.out.println("请输入一串字符,其中首字符为需要打印的字符"); String s=sc.next(); char cc=sc.charAt(0); if((‘a‘<=cc&&cc<=‘z‘)||(‘A‘<=cc&&cc<=‘Z‘)){ System.out.println(cc+"输入为字符"); } else{ System.out.println(cc+"输入不为字符"); } } }
- Array
- The array knowledge is basically the same as the C language, but Java does not allow the number of array elements to be specified within the square brackets in the declaration array.
a.lengthThe length of the array a
- If you traverse all the data in a collection, you can also use the Foreach Loop Note: The Foreach loop is used only to read each element in the array and cannot be used to modify the element values of the array.
for(int x:a) System.out.println(x); //依次把数组a的每一个元素赋值给x变量,在循环体中可以对x变量进行处理
Such as:
for(int i=0;i<a.length;i++){ a[i]=i*i; }//通过循环修改数组的元素值
- Operator: Basic reference to the C language, note the priority of operations
- Sentence Learning:
- If conditional branching statement
- Switch Switches statement
- Looping statements
- Break and Continue statements
- For statements and arrays
Problems in teaching materials learning and the solving process
- Question 1: Use of the basic type conversion method and the problem of lack of precision?
- Problem 1 Solution:
- First, the Boolean type cannot be converted to another type. Integers, decimals, and character types can be converted to each other.
- Automatic type conversion: byte→short→int→long→float→double char→int→long→float→double but may lose precision
- Coercion Type conversions: You can force type conversions when automatic type conversions are not possible. (1) Conversions between decimals and integers:
double dd=3.121; int ii; ii=(int)dd; System.out.println(ii);//此时double类型转换为int类型,输出结果为3。
(2) When a large integer type is converted to a small integer type, only the corresponding low-order byte is converted, and a data error may occur.
int ii=270; byte bb; bb=(byte)ii; System.out.println(bb); /*此时输出bb=14,因为ii变量在计算机中存储形式为: 0000 0000 0000 0000 0000 0001 0000 1110 把ii强制转换为byte类型,只把最后一个字节的数存储到bb变量中,bb变量中存储的内容为:0000 1110 即为14.*/
(3) integers can be turned into characters
int ii=110; char cc=(char)ii; System.out.println(cc); //此时输出为n,因为n的ASCII码值为110。
(4) The expression can be cast:
byte bb=123; bb=(byte)(bb+1); System.out.println(b );
Code Hosting
Last week's summary of the wrong quiz
- Error 1 and why, understand the situation: how to do Javac and Java related operations in the root directory, such as: how to compile *. Java files in the bin directory
javc -d ./bin scr/Hello.java how to run the *.class file in the is5324 package in the bin directoryjava -cp .:bin is5324.Hello
- The wrong question 2 and reason, understand the situation: if just to run Java program, download program which install? The JRE should be selected. Analysis: The Java program requires only the JRE to run, while the Java program development requires the JDK.
Learning progress Bar
|
lines of code (new/cumulative) |
Blog Volume (Add/accumulate) |
Learning Time (new/cumulative) |
Important Growth |
| Goal |
3000 rows |
30 Articles |
400 hours |
|
| First week |
203/203 |
1/1 |
15/15 |
|
| Second week |
326/529 |
2/3 |
12/27 |
|
Resources
20165324 "Java Programming" the second week