hands -on brain, self-confidence, achievement life
hands on the brain 1
? Read the example carefully : Enumtest.java , run it, analyze the running results?
Package demo;
Public class Test {
Public Static void Main (string[] args) {
Size s=size. SMALL;
Size t=size. LARGE; S and T refer to different objects
System. out. println (s==t); False
System. out. println (S.getclass (). isprimitive ()); False is not the original data type
Size u=size. valueOf ("SMALL"); Convert from String
System. out. println (S==u); True
for (Size value:size. Values ()) {//list all of its values
System. out. println (value);
}
}
}
enum size{SMALL,MEDIUM,LARGE};
Operation Result: SMALL MEDIUM LARGE
? What conclusions can you get? Have you mastered the basic usage of enum types?
Constants of enumerated types are stored in the order of strings, size value:Size.value () can traverse all values in size, int ordinal () can return its position in the enum (enumerate), constructor and overwrite ToString () Method can assign values to an enumeration type ...
hands on the brain 2
? to be What ? Double class type of the number value in The line operation is not "mathematically accurate". Knot The fruit?
Both single-precision and double-precision storage in the computer is divided into three parts: the sign bit (0 for positive, 1 for negative), the digit (for storing the exponential data in scientific notation, and the use of shift storage), and the tail part of the number. For example, the scientific notation of 8.25 and 120.5 is expressed as: decimal 8.25*10^0, 1.205*10^2, binary 1.0001*2^3, 1.1101101*2^6, these numbers are stored in binary form in the computer, will appear 00110011001100110011 ... Infinite loop Series, the error occurs when the data type is converted, and the decimal data (such as 2.25) can be represented in binary notation, which does not exist. (This section refers to the blog Park [email protected]).
hands on the brain 3
? what is the output of the following code?
int x=100;
int y=200;
System.out.println ("x+y=" +x+y);
System.out.println (x+y+ "=x+y");
Output Result: x+y=100200 300=x+y
? Why is there such an output result
Output Statement 1 "+" for the connection operation, with ("x+y=" + (x+y)), different, the output string "x+y=" and X and Y, output statement 2 in the first "+" is the addition operator, the second "+" is the connection operator.
hands on the brain 4
? Write a program, the user input two number, to find out its subtraction, and the message box to display the calculation results
Package demo;
import Javax.swing.JOptionPane;
Public class test{
Public Static void Main (string[] args) {
int N1=integer. parseint (Joptionpane. Showinputdialog ("Input number 1:");
int N2=integer. parseint (Joptionpane. Showinputdialog ("Input number 2:")) Gets the value entered from the Joptionpane.showinputdialog dialog box and then converts to the int type
Joptionpane. Showmessagedialog (null, "The sum is:" + (N1+N2)
+ "\ n" + "The difference is:" + (N1-N2)
+ "\ n" + "The product is:" + (N1*N2)
+ "\ n" + "the Division is:" + (N1/N2));
}
}
The result is:
Operation of the brain and Java program using the number of message boxes