Window Popup
Two-number Add window popup Zhang She Qi 2015/10/3
Import Javax.swing.JOptionPane;
public class Addition {
public static void Main (string[] args) {
TODO auto-generated method stubs
String Firstnumber,secondnumber;
int Number1,number2,sum,jian,cheng,chu;
Firstnumber=joptionpane.showinputdialog ("Enter first integer");//prompts for number one on the window
Secondnumber=joptionpane.showinputdialog ("Enter second integer");//Prompts for the second number on the window
Number1=integer.parseint (Firstnumber);
Number2=integer.parseint (Secondnumber);//convert input number to int type
sum=number1+number2;//summation
jian=number1-number2;//to seek difference
cheng=number1*number2;//to find the product
chu=number1/number2;//Business
Joptionpane.showmessagedialog (NULL, "and as:" +sum+ "The difference is:" +jian+ "Product:" +cheng+ "quotient:" +chu, "Results", Joptionpane.plain_ MESSAGE);//Display the results on the window
System.exit (0);//Free space
}
}
Operation Result:
Hands on the brain
(a) Read the example carefully : Enumtest.java, run it, analyze the running results?
What conclusions can you get? Have you mastered the basic usage of enum types?
A 2015/10/3 of Snow and Sunshine
public class Exercise {
public static void Main (string[] args) {
TODO auto-generated method stubs
Size S=size.small;
Size T=size.large;
System.out.println (s==t);
System.out.println (S.getclass (). isprimitive ());
Size u=size.valueof ("SMALL");
System.out.println (S==u);
For (Size value:Size.values ()) {
System.out.println (value);
}
}
}
Enum Size{small,medium,large};
Basic usage of enum types:
1. In fact, the enumeration type is also a class, directly following the Java.lang.Enum class, the method of owning this class.
2. Enumeration types can be used in a switch statement.
3. Because the variable has only one value, select a value in the enumeration type to assign the value.
Example: Size s=size.small;
Size T=size.large;
4. Enumeration types can use functions of the parent class directly.
Example:ordinal(),valueOf() and name(), andso on.
5. enum type is a reference type!
6. The enumeration does not belong to the original data type, and each of its specific values refers to a specific object. The same value refers to the same object.
7. You can use the "= =" and the equals () methods directly compared to the value of the enumeration variable, in other words, for the enumeration type of the variable, "= = The result of executing with the equals () method is equivalent.
(b) please run the following code (testdouble.java)
What kind of output did you see, accidentally?
Operation Result:
This is one of the errors that can be caused by using floating-point types.
(c) 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");
Why is there such an output result?
The former is a string connection, as long as the x+y on the back of the parentheses can be output .
The latter one is the meaning of the numbers added.
Java window pop-up and hands-on brain