JAVA编程思想 第2章习题解答

来源:互联网 发布:广东毕业生就业数据 编辑:程序博客网 时间:2024/05/18 01:47

(1)

public class HelloWorld
{
   public static void main(String str[])
   {
      System.out.println("Hello World!");
   }
}

(2)

import java.util.Scanner;
public class Print
{
   public static void main(String[] args)
   {
       System.out.println("请输入姓名:");
       Scanner sr=new Scanner(System.in);
       String name=sr.nextLine();
       System.out.println("请输入年龄:");
       int age=sr.nextInt();
       System.out.println("请输人分数:");
       float score=sr.nextFloat();
    }
}
       

(3)

//: Property.java


import java.util.*;


/** The first Thinking in Java example program.
  * Lists system information on current machine.
  * @author Bruce Eckel
  * @author http://www.BruceEckel.com
  * @version 1.0
*/
public class Property{
   /** Sole entry point to class & application
    * @param args array of string arguments
    * @return No return value
    * @exception exceptions No exceptions thrown
   */
public static void main(String[] args){
  System.out.println(new Date());
  Properties p=System.getProperties();
  p.list(System.out);
  System.out.println("---Memory Usage:");
  Runtime rt=Runtime.getRuntime();
  System.out.println("Total Memory="
                     + rt.totalMemory()
                     + "Free Memory= "
                     + rt.freeMemory());
  }
}///:`



(4)

 public class HelloWorld
{
  /**
   *HelloWorld.java
   *这是一个简单的Java应用程序
   */
  
  //public修饰的类为主类
   public static void main(String str[])

   {
      System.out.println("Hello World!");
   }
}




我发现一个文件夹下只能有一个doc文件夹,javadoc  HelloWorld源程序产生一个doc文件夹,但是Javadoc Property源程序产生的doc文件夹不见了。。。









阅读全文
1 0