First, the hands-on brain 1
1, Issue: read Example: EnumTest.java, run it, run the analysis results? What conclusions can you get? You have mastered the basic usage of enumeration types yet?
2, as follows:
. 1 public class EnumTest { 2 . 3 public static void main (String [] args) { . 4 Size S = Size.SMALL; . 5 Size t = Size.LARGE; . 6 // S and t refer to the same object? . 7 System.out.println (S == T); // . 8 // primitive data type? . 9 System.out.println (s.getClass () isPrimitive ().); 10 // converts from a string . 11 Size Size.valueOf U = ( "the SMALL" ); 12 is System.out.println (== U S ); // to true 13 // List of all its values 14 for (Size value: Size.values ()) { 15 System.out.println (value); 16 } . 17 } 18 is . 19 } 20 is 21 is enum Size { 22 is the SMALL, MEDIUM,, the LARGE 23 is };
3, the results Screenshot
4 Conclusion
① enumeration of different addresses of different elements of the instantiated objects
Enum same element converted from the character string ② instantiated object assigned to a new variable and the address of the original variables
Second, the hands-on brain 2
1, issue:
What is the output of the following code? Why is this output?
1 public class Test { 2 public static void main(String[] args) { 3 int X=100; 4 int Y=200; 5 System.out.println("X+Y="+X+Y); 6 System.out.println(X+Y+"=X+Y"); 7 } 8 }
2, the results Screenshot
3. Conclusion
In System.out.println () output statement "+" character string used to connect, for example, the output of the first line "X + = Y" X + Y + Y and X is the connection number of characters in the right-hand side plus string of symbols, the output is 100,200;
Plus sign may also be used to perform algebraic operations, but the operations performed between the digital To parentheses.
Third, classroom test 1,2
Classroom Test 1: like two pillars that, take twenty minutes to write an automatically generated 30 primary four operations entitled "Software"
Class Test 2: (1) subject to avoid duplication;
(2) can be customized (number / printing mode);
code show as below:
1 import java.util.Random; 2 import java.util.Scanner; 3 4 public class ceishi { 5 static Scanner sc = null; 6 static String a3 = new String(" "); 7 public static int s1 = new Random().nextInt(100); 8 public static int s2 = new Random().nextInt(100); 9 public static int s3 = new. The Random () the nextInt (100 ); 10 public static int A [] [] = new new int [100000] [2 ]; . 11 public static int S [] = new new int [100000 ]; 12 is 13 is public static void main (String [] args) { 14 SC = new new Scanner (the System.in); 15 System.out.println ( "Please enter the number of Title:" ); 16 int n-= sc.nextInt (); . 17 System.out.println ( " Please enter the number of questions per line: " ); 18 int m = sc.nextInt(); 19 for (int i = 0; i < n; i++) { 20 if ((i) % m == 0) 21 System.out.print("\n"); 22 System.out.print((i + 1) + ":"); 23 s1 = new Random().nextInt(100); 24 System.out.print(s1); 25 s2 = new Random().nextInt(100); 26 s3 = new Random().nextInt(100); 27 // 重复 28 a[i][0] = s1; 29 a[i][1] = s3; 30 s[i] = s2; 31 for (int j = 0; j < i; j++) { 32 if (a[j][0] == s1 && a[j][1] == s3 && s[j] == s2) { 33 s3 = new Random().nextInt(100); 34 while (s3 == a[i][1]) { 35 s3 = new Random().nextInt(100); 36 } 37 s3 = new Random().nextInt(100); 38 while (s3 == a[i][1]) { 39 } 40 } 41 } 42 if (s2 % 4 == 0) 43 System.out.print("+"); 44 if (s2 % 4 == 1) { 45 System.out.print("-"); 46 while (s1 < s3) { 47 s3 = new Random().nextInt(100); 48 } 49 } 50 if (s2 % 4 == 2) { 51 System.out.print("*"); 52 while (s1 * s3 >= 100) { 53 s3 = new Random().nextInt(100); 54 } 55 } 56 if (s2 % 4 == 3) { 57 System.out.print("/"); 58 while (s3 != 0 && s1 / s3 != 0) { 59 s3 = new Random().nextInt(100); 60 } 61 } 62 System.out.print(s3); 63 System.out.print("="); 64 System.out.print(a3); 65 } 66 } 67 }