Package after class exercises; import Java.util.scanner;import java.util.*; Public classhands-on brain _ random integer { Public Static voidMain (String[]args) {System. out. println ("Please enter the number of random numbers you want to generate:"); Scanner SC=NewScanner (System.inch); inty=Sc.nextint (); for(intI=0; i<y;i++) { intX= (int) (Math.random () * +)+1; System. out. println (x); }}}
This procedure uses the method Math.random (), which is used to produce a 1-1000 integer, which defines the number of integers to be produced.
Package after class exercises; Public classhands-on brain _ observation code { Public Static voidMain (string[] args) {System. out. println ("The square of the integer 7 is"+ Square (7)); System. out. println ("\nthe square of double 7.5 is"+ Square (7.5)); } Public Static intSquareintx) {returnX *x; } Public Static DoubleSquareDoubley) {returnY *y; }}
The special thing about this program is that two methods use the same method name, square, and then, although the method name is the same, the final result is different. It is calculated with integer 7 and calculated by floating-point number 7.5, which means that the function can be calculated according to the different parameter types and the number of parameters if the parameter type or parameter number is not the same or the argument type is not the same.
Viewing the System.out.println () method in the JDK finds that many types can be entered in the argument table in the System.out.println () method.
Hands on the brain-2