Learn from scratch Java-2. Get a preliminary understanding of how Java programs make work, java-2java

Source: Internet
Author: User
Tags square root

Learn from scratch Java-2. Get a preliminary understanding of how Java programs make work, java-2java

1. Learn how Java applications work

2. Construct an application

3. Pass parameters to the application

4. Learn how Java programs are organized

5. Create an object in the Application

Program Root: output the positive square Root of 225

1 package com. jsample; // The application is located in the jsample package in 2 3 public class Root {4 public static void main (String [] args) {5 int number = 225; // variable number Storage 255 6 System. out. println ("The square root of" // display The integer and Its square root 7 + number 8 + "is" 9 + Math. sqrt (number) // display the square root 10); 11} 12}
View Code

Program AnotherRoot: output the positive square root of 625

1 package com. jsample; 2 3 public class AnotherRoot {4 public static void main (String [] args) 5 {6 int number = 625; 7 System. out. println ("The square root of" // display The integer and Its square root 8 + number 9 + "is" 10 + Math. sqrt (number) 11); // display the square root 12} 13}
View Code

Program blank filler: PASS Parameters and fill in the blanks

1 package com. jsample; 2 3 public class AnotherRoot {4 public static void main (String [] args) 5 {6 int number = 625; 7 System. out. println ("The square root of" // display The integer and Its square root 8 + number 9 + "is" 10 + Math. sqrt (number) 11); // display the square root 12} 13}
View Code

Program NewRoot: Pass the parameter, convert it to double type, and output its positive square root

1 package com. jsample; 2 3 public class NewRoot {4 public static void main (String [] args) 5 {6 System. out. println ("The square root of" // display The integer and Its square root 7 + args [0] 8 + "is" 9 + Math. sqrt (Double. parseDouble (args [0]) // display the square root, but Java stores all the parameters 10 at runtime); // store as a string and convert it to 11} 12}
View Code

 

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.