Java Experiment Report 2: Use of Java Symbols and Expressions

Java Experiment Report 2: Use of Java Symbols and Expressions

1. The purpose of the experiment

1. Familiar with the correct use of Java language operators and expressions.
2. Familiar with basic data types and their occupied space, familiar with the definition characteristics of identifiers;
3. Master the principles of assignment and conversion of different types of data, and familiar with the meaning of automatic conversion and forced conversion

2. Experimental content

1. Experimental steps:
⑴. Design programs, practice and use Java operators
⑵. Design a program, practice and use Java's escape characters, automatic type conversion, and mandatory type conversion.
⑶. Record the source program and running results, and verify the use of Java symbols and expressions.
2. Program and operation results:
⑴. design run program

  public class Operators {
    
    
	  public static void main(String[] args){
    
    
		  int x = 97,y = 20;
		  double m = 9.3,n =6.2;
		  char z = 'a';
		  System.out.println(x+y*m-n/x); //基本运算符运算
		  System.out.print(z+"\t");
		  System.out.println(z);         //转义字符
		  System.out.println(9.0/100);     //自动转换
		  System.out.println((char)x == z); //强制转换
	  }
}

⑵. The screenshot of the experimental program running is as follows:
insert image description here

3. Experimental experience

Through this experiment, I learned that the basic data types of the Java language include integer types (byte, short, int, long), character types (char), floating point types (float, double), and Boolean types (boolean). The following automatic conversion rules.
byte  short  char  int  long  float  double
According to the direction shown by the arrow, the data of the data type on the left can be automatically converted and assigned to the variable of the data type on the right, but vice versa, it will be on the right Assignment of data of the data type to a variable of the data type on the left must be converted. Moreover, the complement type cannot be converted to other types, and casting during assignment may result in loss of precision.
At the same time, Java is a strongly typed language. Variables must be declared before they are used to allow the system to allocate memory. There are certain naming rules when naming. Its operators are divided into unary operators, binocular operators and ternary operators. What we need to pay attention to is that they have a certain priority in the operation. When the variable data type is different during the operation, it will be automatically converted according to the rule table, and its escape characters will automatically escape the corresponding effect according to the ASCII code when outputting. At the same time, in addition to basic data types, Java also has reference data types, also known as composite data types.

Guess you like

Origin blog.csdn.net/qq_41866091/article/details/92384006