I hope you will give us your criticism and be grateful for it (not finished, to be continued ...). )
In chapter three, exercise 9 (1) shows the maximum and minimum numbers that can be represented by the float and double exponential notation respectively.
public class Maxminfloatdouble { /** * @param args */public static void Main (string[] args) { //TOD O auto-generated Method Stub Float fmax = float.max_value; float fmin = float.min_value; Double dmax = double.max_value; Double dmin = double.min_value; System.out.println (Fmax); System.out.println (fmin); System.out.println (DMAX); System.out.println (dmin); /*result: 3.4028235E38 1.4E-45 1.7976931348623157E308 4.9e-324*/ } }
Exercise (10) write a program with two constant values, one with alternating bits 1 and 0, where the least significant bit is 0 and the other has alternating bits 1 and 0, but the least significant bit is 1 (hint: Use hexadecimal constants to represent the simplest method). Take two values, Use bitwise operators to combine them in all possible ways, and then use Integer.tobinarystring () to display
public static void Main (string[] args) { int i1 = 0XAAAAAAAA; int i2 = 0x55555555; System.out.println (integer.tobinarystring (I1)); System.out.println (integer.tobinarystring (I2)); /** * Result * 101010101010101010101010101010101010101010101010101010101010101 */ }
Exercise 14 (3) writes a method that receives two string arguments, compares the two strings with a comparison of the various Boolean values, and then prints the results. do = = and! = At the same time, test with equals (). This method is called with several different string objects inside main ().
/** * @param args */public static void main (string[] args) {String str1= "Hello"; String str2= "word"; String Str3=new string ("Hello"); Teststr (str1, str2); System.out.println ("--------------------------"); Teststr (str1, STR3);} public static void Teststr (String s1,string s2) {//boolean B1=s1>s2;//boolean b2=s1<s2;boolean b3=s1==s2; System.out.println (s1+ "= =" +s2+ ": \ T" +B3); Boolean b4=s1.equals (S2); System.out.println (s1+ ". Equals (" +s2+ "): \ T" +B4); Boolean b5=s1!=s2; SYSTEM.OUT.PRINTLN (s1+ "! =" +s2+ ": \ T" +b5);/**result * * hello==word:falsehello.equals (word): falsehello!= Word:true--------------------------hello==hello:falsehello.equals (hello): Truehello!=hello:true */}
Fourth. Exercise 1: (1) write a program that prints values from 1 to 100
public static void Main (string[] args) {test (100);} public static void Test (int num) {int i=0;while (i<num) {System.out.print (++i), if (i!=100) {System.out.print (",");}} SYSTEM.OUT.PRINTLN (); int J=0;do{system.out.print (++J), if (j!=100) {System.out.print (",");}} while (j<100); System.out.println (); for (int k=0;k<100;) {System.out.print (++k), if (k!=100) {System.out.print (",");}}}
Exercise 2: (2) write a program that generates 25 random numbers of type int, and for each random number, use the If-else statement to classify it as greater than, less than, or equal to a randomly generated value immediately following it.
public static void Main (string[] args) {test ();} public static void Test () {int num[] =new int[25];for (int i=0;i<25;i++) {random r=new random (); int n=r.nextint (); Num[i] =n;if (i>0) {compare (Num[i-1],num[i]);}}} public static void Compare (int n1,int n2) {//system.out.println (n1+ "," +n2+ "\ n n1>n2:" + (N1>N2) + "\ T" + "N1==N2:" + ( N1==N2) + "\ T" + "N1<N2:" + (N1<N2)), if (n1>n2) {System.out.println (n1+ "greater than" +n2);} else if (n1<n2) {System.out.println (n1+ "less than" +n2);} else {System.out.println (n1+ "equals" +n2);}}
Exercise 3: (1) Modify Exercise 2 to include the code in a while infinite loop. Then run it until you break it with the keyboard (usually by pressing CTRL + C).
Exercise 4: (3) write a program that uses two nested for loops and the remainder operator (%) to detect and print a prime number (an integer that can be divisible only by itself and 1 and not by other numbers).
Exercise 5: (4) Repeat Exercise 10 in chapter 3rd, instead of using the integer.tobinarystring () method, use the ternary and bitwise operators to display the binary 1 and 0.
Java Programming Ideas Personal exercises