day01 - Assessment Question daily assignment - JavaSE day 1

Keywords: Java Back-end

## choice question

### Topic 1 (single choice):

**The following are computer hardware(  D  )**

#### Options:

​	A. QQ

​	B.WeChat

​	C.FeiQ 

​	D.CPU



### Topic 2 (single choice):

**The following can be guaranteed java Programs run across platforms( A  )**

#### Options:

​	A. JVM(java virtual machine)

​	B. Windows system

​	C. Linux system

​	D. MACOS system



### Topic 3 (single choice):

**The following about JDK,JRE,JVM The description is correct( B )**

#### Options:

​	A. JVM Contains JRE,JRE Contains JDK

​	B.JDK Contains JRE,JRE Contains JVM

​	C.JRE Contains JVM,JVM Contains JDK

​	D.The three have no inclusive relationship



### Topic 4 (single choice):

**According to the computer hardware architecture proposed by von Neumann, the following statement is correct( B )**

#### Options:

​	A.Arithmetic unit, register, memory, input device, output device

​	B.Arithmetic unit, controller, memory, output device, output device

​	C.B\S framework C\S framework

​	D.All the above descriptions are wrong



### Topic 5 (single choice):

**About will JDK Configure to Path Environment variables, the following description is correct( C)**

#### Options:

​	A. In order to be accessible in any directory .java file

​	B. In order to be accessible in any directory .class file

​	C. In order to be accessible in any directory jdk in bin Catalog tools

​	D. All the above descriptions are wrong



### Topic 6 (single choice):

**Which of the following is the correct single line comment( A )**

#### Options:

​	A. //

​	B./* */

​	C./** */

​	D.



### Topic 7 (multiple choices):

**The correct description of the following notes is(  AC )**

#### Options:

​	A. Comments are words that explain the code

​	B. It is absolutely not allowed to write code in comments

​	C. The annotated content will not participate in the compilation and execution of the program

​	D. There are only single line comments and multi line comments



### Topic 8 (single choice):

**The following about IDEA The hierarchy statement is correct( D )**

#### Options:

​	A. class --- module --- project --- package

​	B. package --- module --- project --- class

​	C. module --- project --- package --- class

​	D. project --- module --- package --- class



### Topic 9 (single choice):

**Which of the following is idea Generated correctly in main Shortcut letter for method( D )**

#### Options:

​	A. sout Hit enter

​	B.alt + m

​	C.ctrl + m

​	D.psvm Hit enter



### Topic 10 (single choice):

**Which of the following is idea Correctly generate shortcut letters for output statements in( A )**

#### Options:

​	A. sout Hit enter

​	B.alt + m

​	C.ctrl + m

​	D.psvm Hit enter

Daily assignment - JavaSE day 1

Topic 1 (training)

Please write a program to output the following statements to the screen:

java Is a cross platform computer language
 It is called write once, run everywhere

Training objectives

The syntax format and compilation run of HelloWorld case in java language.

Training tips

1. Create a java file.

2. Write a class to complete the program.

3. The operation of the program needs the main method, and write the main method.

4. What statement should be used to output the text in the title?

5. How to compile and run java files?

Reference scheme

Imitate the HelloWorld case

Training steps

1. Create a new text file and change the name to Test01.java. Pay attention to the suffix of the file to prevent the file name of Test01.java.txt from appearing.

2. Open the file and write the code. First define a class Test01. The class name should be consistent with the file name. Pay attention to case.

3. Define the main method in the class, write the output statement in the main method, and wrap the text in the title in double quotation marks.

4. Save the contents of the file. Open the cmd window and switch the command directory to the directory where the file is located. Use the javac command to compile the java file, and use the Java command to run the class file to view the results. Note: when compiling the java file, the suffix name is required; when running the class file, the suffix name is not required.

Reference answer

public class Test01 {
    public static void main(String[] args) {
        System.out.println("java Is a cross platform computer language");
        System.out.println("It is called write once, run everywhere");
    }
}

Topic 2 (application)

Please write a program to output the personal information of a student to the screen. The information includes name (string constant), gender (character constant), age (integer constant), height (unit meter, decimal constant) and marriage (Boolean constant). The output format is as follows:

Zhang San
 male
18
1.78
false

Training objectives

Constants in java

Training tips

1. Create a java file.

2. Write a class to complete the program.

3. The operation of the program needs the main method, and write the main method.

4. If you need to use output statements to output information, how should you write all kinds of information?

5. How to compile and run java files?

Reference scheme

Use the output statement to output constants directly

Training steps

1. Create a new text file and change the name to Test02.java.

2. Open the file and write the code. First define a class Test02. Write the main method in the class.

3. Output various information in the output statement.

3.1. The name is a string constant, wrapped in double quotation marks.

3.2. Gender is a character constant, wrapped in single quotation marks. Of course, you can also use a string, wrapped in double quotation marks.

3.3. Age is an integer, and the integer is output directly.

3.4. The height is decimal, and the floating-point type is output directly.

3.5. Married or not, yes or no, there are only two states. It is suitable to use Boolean type, and directly output true or false of boolean type.

4. Save the contents of the file. Open the cmd window and switch the command directory to the directory where the file is located. Use the javac command to compile the java file, and use the Java command to run the class file to view the results. Note: when compiling the java file, the suffix name is required; when running the class file, the suffix name is not required.

Reference answer

public class Test02 {
    public static void main(String[] args) {
        System.out.println("Zhang San"); // Output string constant, name
        System.out.println('male'); // Output character constant, gender
        System.out.println(18); // Output integer constant, age
        System.out.println(1.78); // Output decimal constant, height
        System.out.println(false); // Output Boolean constant, no
    }
}

Topic 3 (training)

Please write a program to define variables of 8 basic data types and print the values of variables.

Training objectives

Definition of eight basic data types and variables in java

Training tips

1. What are the eight basic data types in java?

2. What is the format for defining variables?

3. How should variable names be defined?

4. How do I use variables?

Reference scheme

Define the variable and output the value of the variable.

Training steps

1. Create a java file, define the class Test03, and write the main method.

2. In the java language, the data type of a variable must be specified when defining a variable. There are eight basic data types, including byte, short, int, long, float, double, char and boolean.

3. The format of defining variables is:

Data type variable name = initialize value; // Declare variables and assign values
// or
 Data type variable name; // First statement
 Variable name = initialize value; // Reassignment

4. It can contain English letters, numeric characters, English underscore () and English dollar sign ($), and cannot start with a number. In development, the naming of java variables should preferably comply with the "small hump" Convention, and it is best to see the meaning of the name.

5. In the output statement, you can call the variable name directly.

6. Compile and run the code to see the output.

Reference answer

public class Test04 {
    public static void main(String[] args) {
        // Define a byte type variable. The value is an integer, as long as it is in the byte range: - 128 ~ 127
        byte b = 100;
        System.out.println(b);
		// Define a variable of short type, whose value is an integer, as long as it is in the short range
        short s = 12345;
        System.out.println(s);

        // The default type of an integer is int
        int num = 654321;
        System.out.println(num);

        // To define an integer of type long, you need to add a letter (L) after the data. Case is unlimited. Uppercase is recommended.
        long lo = 123456789L;
        System.out.println(lo);

        // To define floating-point numbers of float type, you need to add the letter (F) after the data. The case is unlimited. Uppercase is recommended.
        float f = 1.5F;
        System.out.println(f);

        // Floating point default type double
        double d = 123.456;
        System.out.println(d);

        // Boolean has only two values: true and false
        boolean b1 = true;
        boolean b2 = false;
        System.out.println(b1);
        System.out.println(b2);

        // Defining a character type requires a pair of English single quotation marks, and can contain only one character
        char c = 'a';
        System.out.println(c);
    }
}

Topic 4 (application)

Please select the appropriate data type to define the variable and output the value of the variable according to the following description.

1. There are 100 students in the class.

2. The price of a commodity is 55.55 yuan.

3. The earth has been born for more than 4.6 billion years.

4. The description of "5 is an even number" is false.

The output results are as follows:

100
55.55
4600000000
false

Training objectives

Definition of variables

Training tips

1. Different data types need to be used for different data information. Appropriate types can be selected according to the size and characteristics of different data types to define variables and describe the information of things.

Reference scheme

Define variable description information.

Training steps

1. Create a java file, define the class Test04, and write the main method.

2. Define different variables in the main method to describe the information in the topic.

2.1. The number of students can be represented by the default integer type int

2.2. The commodity price is represented by the default floating-point number type double

2.3 astronomical figures can be represented by long integer

2.4. A description is true or false. There are only two states. boolean type can be used

3. Use the output statement to output variables.

4. Compile and run to see the output.

Reference answer

public class Test04 {
    public static void main(String[] args) {
        int studentNumber = 100; // Number of students
        System.out.println(studentNumber);

        double price = 55.55; // commodity price
        System.out.println(price);

        long yearNumber = 4600000000L; // Integer out of int range
        System.out.println(yearNumber);

        boolean flag = false; // True and false value
        System.out.println(flag);
    }
}

Topic 5 (error finding)

There are the following code snippets in the main method:

// Segment 1
int a = 10;
{
    a = 20;
    System.out.println(a);
}

// Segment 2
{
    int b = 20;
    System.out.println(b);
}
b = 30;
System.out.println(b);

Please analyze the code in which the error will occur, describe the cause of the error, and correct it. Write the corrected code into the Test05.java file to view the running results.

Training objectives

Valid scope of variable

Training tips

1. The valid range of a variable is only valid in a pair of curly braces {} that directly wrap the variable.

Reference scheme

Training steps

1. In fragment 1, the variable a is defined under the braces of the main method, so it can be used in the whole main method (including the inner braces). There is no problem.

2. Variable b in fragment 2 has no problem in the first output and does not exceed its effective scope; When changing its value, it has exceeded the valid range of b, and variable b can no longer be used. Variable resolution can be redefined.

3. Create a java file, define the class Test05, and write the main method. Write the modified code in the main method, compile and run to see the effect.

Reference answer

public class Test05 {
    public static void main(String[] args) {
        // Segment 1
        int a = 10;
        {
            a = 20;
            System.out.println(a); // Normal output 20, no error
        }
        
        // Segment 2
        {
            int b = 20;
            System.out.println(b); // Normal output 20, no error
        }
        // b = 30; //  An error is reported here. B has exceeded its valid range
        int b = 30; // You need to redeclare variable b of type int
        System.out.println(b);
    }
}

Topic 6 (application)

In java, the arithmetic operator plus sign "+" can also be used as a string connector. It can connect multiple strings together to form a new string, or connect other data types with strings to form a new string. Please read the following explanation:

/*
When we output HelloWorld, the output statement is:
System.out.println("HelloWorld");
In fact, this output statement outputs a string, which can also be composed of two or more strings. For example:
System.out.println("Hello" + "World");
Here, the two strings will be spliced into one and then output. The result is consistent with the above. Another example:
int age = 20;
System.out.println("My age is "+ age); 
In the above output statement, variables of type int are connected with strings to form a new string. The output result of the program is:
My age is 20
 Moreover, multiple data can be connected with a string, for example:
int height = 180;
System.out.println("My age is "+ age +" and my height is "+ height"; 
In this statement, two strings and two variables will be combined into a string output, and the output result is:
My age is 20 and my height is 180
*/

According to the above description, please write a program to define two integer (int type) variables, sum the two integers, and output the results to the screen. The output format is as follows:

10 + 20 = 30

Training objectives

Definition and use of variables, string connectors.

Training tips

1. To sum two integers, you need to define variables to store two integers.

2. The result can be obtained by adding and summing the two variables, but it needs to be output in the format required by the topic. What should I do? According to the title description, it can be spliced into a string.

Reference scheme

Training steps

1. Create a java file, define the class Test06, and write the main method.

2. In the main method, define two variables of type int.

3. Define the third variable, add the first two variables and assign values to the third variable.

4. Spell the format required by the topic and output the results. According to the title description, if num1 and num2 variables are defined with values of 10 and 20 respectively, the formula of output 10 + 20 should be written as: num1 + "+" + num2, where num1 and num2 are two variables, and the "+" in the middle is in string format.

5. Save the file, compile and run, and view the results.

Reference answer

public class Test06 {
    public static void main(String[] args) {
        int a = 10; // Define integer variable a
        int b = 20; // Define integer variable b
        int c = a + b; // Define the integer variable c and assign the result of a + b to c
        System.out.println(a + " + " + b + " = " + c); // Splicing variables and strings in an output statement
    }
}

Topic 7 (application)

In today's course, we know eight basic data types of java. With the follow-up study, we will also learn to reference data types. At this time, due to the needs of practice, we need to understand one of the most commonly used reference data types - String. One definition method of String variable is consistent with the basic data type:

// Data type variable name = initialization value;
String str = "China";
System.out.println(str);
// Where String is the data type, str is the variable name (only if it complies with the identifier rules), and "China" is the String constant value we learn.
// In general, it means that the string "abc" is assigned to the variable str of string type.
// Output result: China

According to the above description, select the appropriate data type to define variables to describe a student's information and output it to the screen. The output results are as follows:

************************
My name is Zhang San
 My gender is: male
 My age is: 18
 My address is: xx province xx city
 My meal card balance is: 55.55 element
************************

Training objectives

Data type, definition and use of variables, string connector

Training tips

1. According to the requirements of the topic, the student's information includes name, gender, age, address and balance. What data type should these information be stored?

2. In the output statement, in order to output in the format required by the topic, some known strings and variables need to be spliced, such as: "my name is:" + name "

Reference scheme

Training steps

1. Create a java file, define the class Test07, and write the main method.

2. Variables are defined in the main method to store student information.

2.1. Name, gender and address can all use string type

2.2. Age is integer data, and int type is used

2.3. The balance is decimal type and double type is used

3. Concatenate known strings and variables with "+" for output.

4. Save the file, compile and run, and view the results.

Reference answer

public class Test07 {
    public static void main(String[] args) {
        // full name
        String name = "Zhang San";
        // Gender
        String gender = "male";
        // Age
        int age = 20;
        // address
        String address = "Chicago, USA";
        // balance
        double money = 88.88;
        
        System.out.println("************************");
        System.out.println("My name is:" + name); // Splicing variables and strings in an output statement
        System.out.println("My gender is:" + gender);
        System.out.println("My age is:" + age);
        System.out.println("My address is:" + address);
        System.out.println("My meal card balance is:" + money + "element");
        System.out.println("************************");
    }
}

Posted by ludachris on Fri, 03 Dec 2021 09:49:05 -0800