《Java程序设计实践教程》清华大学出版社,第一章实验题。
以下是我输入的:
/*
  Here is another short example.
  Call this file "Example.java".
*/
class Example {
  public static void main (String args[]) {
    int num;// this declares a variable called num
    num = 100; // this assigns num the value 100
    System.out.println("This is num: " + num);
    num = num * 2;
    System.out.print("The value of num * 2 is ");
    System.out.println(num);
   }
}请问有何不妥。
我用的是华军软件园的jdk1.70

解决方案 »

  1.   

    少了一个public 哦!这个类不能运行
    /* 
        Here   is   another   short   example. 
        Call   this   file   "Example.java". 
    */ 
    public class   Example   { 
        public   static   void   main   (String   args[])   { 
            int   num;//   this   declares   a   variable   called   num 
            num   =   100;   //   this   assigns   num   the   value   100 
            System.out.println("This   is   num:   "   +   num); 
            num   =   num   *   2; 
            System.out.print("The   value   of   num   *   2   is   "); 
            System.out.println(num); 
          } 
      

  2.   

    没有任何问题啊!你的程序完全可以运行的。只有public,无所谓的。Java程序中只能有一个类是public的,文件名和这个public类的类名相同。但是,可以没有public类,文件名只要和文件中任意一个类名相同就可以了。