Hands on the brain-2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.