从零自学Java-2.初步理解Java程序使如何工作的

Posted on 2018-03-13 23:12  夜逆尘  阅读(201)  评论(0编辑  收藏  举报

1.学习Java应用程序是如何工作的

2.构成一个应用程序

3.向应用程序传递参数

4.学习Java程序是如何组织的

5.在应用程序中创建一个对象

程序Root:输出225的正平方根

 1 package com.jsample;//应用程序位于jsample包中
 2 
 3 public class Root {
 4     public static void main(String[] args){
 5         int number=225;//变量number存储255
 6         System.out.println("The square root of "//显示该整数及其平方根
 7                 +number
 8                 +" is "
 9                 +Math.sqrt(number)//显示平方根
10         );
11     }
12 }
View Code

程序AnotherRoot:输出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 "//显示该整数及其平方根
 8                 +number
 9                 +" is "
10                 +Math.sqrt(number)
11         );//显示平方根
12     }
13 }
View Code

程序blank filler:传递参数,填空

 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 "//显示该整数及其平方根
 8                 +number
 9                 +" is "
10                 +Math.sqrt(number)
11         );//显示平方根
12     }
13 }
View Code

程序NewRoot:传递参数,转化为double型,并输出其正平方根

 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 "//显示该整数及其平方根
 7                 +args[0]
 8                 +" is "
 9                 +Math.sqrt(Double.parseDouble(args[0]))//显示平方根,然而Java在运行时将所有参数
10         );                                             //存储为字符串,需要转换
11     }
12 }
View Code