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

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

2.构成一个应用程序

3.向应用程序传递参数

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

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

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

 package com.jsample;//应用程序位于jsample包中

 public class Root {
public static void main(String[] args){
int number=225;//变量number存储255
System.out.println("The square root of "//显示该整数及其平方根
+number
+" is "
+Math.sqrt(number)//显示平方根
);
}
}

程序AnotherRoot:输出625的正平方根

 package com.jsample;

 public class AnotherRoot {
public static void main(String[] args)
{
int number = 625;
System.out.println("The square root of "//显示该整数及其平方根
+number
+" is "
+Math.sqrt(number)
);//显示平方根
}
}

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

 package com.jsample;

 public class AnotherRoot {
public static void main(String[] args)
{
int number = 625;
System.out.println("The square root of "//显示该整数及其平方根
+number
+" is "
+Math.sqrt(number)
);//显示平方根
}
}

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

 package com.jsample;

 public class NewRoot {
public static void main(String[] args)
{
System.out.println("The square root of "//显示该整数及其平方根
+args[0]
+" is "
+Math.sqrt(Double.parseDouble(args[0]))//显示平方根,然而Java在运行时将所有参数
); //存储为字符串,需要转换
}
}
上一篇:C++学习之从C到C++


下一篇:logback 常用配置详解