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