Origin and Application of Java
Java features
Variables and operators
1. Data Type:
Java data type classification:
There are several basic data types;
Simple use of String
2. identifier, keyword, constant, and variable:
Identifier naming rules;
Common keywords;
Variable naming rules and how to define and assign values;
Conversion between variables;
Scope and lifetime of variables (an example is provided );
3. Operator priority:
Which types of operations are involved? Which operators are included in each type? priority
4. Input and Output:
Input: Use the variables object to input various types of variables.
Output: Use System. out. println () or System. out. print () to implement output. Difference.
Process control statements (sequence, branch, and loop)
1. Order:
2. Branch:
If-else statement: simple if, if-else, multiple if-else, nested if-else
Switch-case statement: the condition of the switch is special; break usage
3. Loop:
While, do-while,:
Syntax structure; abort condition; endless loop
Exercise Section
1. Define eight variables using eight basic data types, and then output the values of each variable on the console.
2. The student is known to have six basic information items: Student ID, name, gender, age, height, and weight. The student information is input from the keyboard in sequence, and the student details are output.
3. John wants to buy a T-shirt. The unit price and quantity of the T-shirt are input by the user. Li Si wants to buy a tennis ball. The unit price and quantity of the tennis ball are input by the user. The total consumption amount of John and Lee are calculated and output.
4. Enter an integer on the keyboard to calculate the total number of digits.
5. Enter a number and use the if statement to determine the matched number.
If you enter:
1>. Print: The number you entered is 1
2>. Print: The number you entered is 2
3>. Print: The number you entered is 3
Other numbers printed: Invalid numbers entered
Note: Use the if-else and switch methods.
6. Input a year on the keyboard to determine whether the year is a normal year or a leap year.
7. Enter a year on the keyboard and a month (number) to display the number of days of the month.
8. enter a year on the keyboard, and enter a month to calculate the total number of days from the current year, January 1, January 1 (for example, if the input year is 2011 and the month is January 1, March, the total number of days from June 1 to June 1. If the input year is 2004 and the month is, the calculation is based on the total number of days from January 1, to January 1)
9. Set int n to design a Java program and print out 1 + 3 + 5 +... The sum of n. The initial value of Variable n is specified in the program.
10. Implement the following program:
1>. Write a program: Output a right triangle (top triangle). The number of rows is input by the user, as shown in 1:
2>. Write a program: Output a right triangle (lower triangle). The number of rows is input by the user, as shown in figure 2:
3>. Write a program to output a right triangle (lower triangle). The number of rows is input by the user, as shown in figure 3:
11. Calculate the number of all daffodils within 1000.
This program is the Application program. The so-called daffodils refers to a three-digit integer,
The cubes of all its numbers are equal to the number itself.
For example, 371 is the number of daffodils, because 371 = 3*3*3 + 7*7*7 + 1*1*1.
(Int I
Bw = I/100;
Shw = I % 100/10 or I/10% 10;
Gw = I % 10
12. calculate all the complete numbers within 1000.
This program is an Application. The so-called full number is the sum of a number exactly equal to its factors.
For example:
6 is a factor of 1, 2, 3, and 6 = 1 + 2 + 3, so 6 is a complete number.
13. 1 ~ The sum of factorial 5
This program is an Application program ~ The sum of the factorial values of 20,
That is, evaluate the expression 1 + 2! +... + 5! Value
14. Implement a calculator. The user enters two operands and an operator (+,-, *,/, and %) from the keyboard. The system automatically completes the calculation.