mod1ans.lst

来自「Mcgraw-Hill - Java 2 - A Beginner S Guid」· LST 代码 · 共 50 行

LST
50
字号
listing 1
/*    
   Compute your weight on the moon.  
   
   Call this file Moon.java.   
*/    
class Moon {    
  public static void main(String args[]) {    
    double earthweight; // weight on earth  
    double moonweight; // weight on moon   
   
    earthweight = 165;   
  
    moonweight = earthweight * 0.17;  
   
    System.out.println(earthweight + " earth-pounds is equivalent to " +  
                       moonweight + " moon-pounds.");    
   
  }    
}

listing 2
/*  
   This program displays a conversion  
   table of inches to meters. 
 
   Call this program InchToMeterTable.java. 
*/  
class InchToMeterTable {  
  public static void main(String args[]) {  
    double inches, meters; 
    int counter; 
 
    counter = 0; 
    for(inches = 1; inches <= 144; inches++) { 
      meters = inches / 39.37; // convert to meters 
      System.out.println(inches + " inches is " + 
                         meters + " meters."); 
 
      counter++; 
      // every 12th line, print a blank line        
      if(counter == 12) { 
        System.out.println(); 
        counter = 0; // reset the line counter 
      } 
    } 
  }  
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?