正在加载图片...
/Sum.java 2 Sum.java /Counter-controlled repetition with the for structure 3 /Java extension packages 5 import javax.swing.JOptionPane 7 public class Sum{ increment number by 2 each iteration 9 /main method begins execution of Java application 10 public static void main(String args[] 11 12 int sum =0; 13 14 /sum even integers from 2 through 100 15 for(int number-2;number<=100;number¥=2) 16 sum +number; 17 18 /display results 19 JOptionPane.showMessageDialog(null,"The sum is"+sum, 20 "Sum Even Integers from 2 to 100" 21 JOptionPane.INFORMATION MESSAGE ) 22 23 System.exit(0); /terminate the application 2 5 }/end method main 2 7 }//end class Sum Sum Even Integers from 2 to 100 The sum is 2550 OK ©2006计算机系杨群 All rights lefts reserved.©2006 计算机系 杨厚群 All rights & lefts reserved. 1 // Sum.java 2 // Counter-controlled repetition with the for structure 3 4 // Java extension packages 5 import javax.swing.JOptionPane; 6 7 public class Sum { 8 9 // main method begins execution of Java application 10 public static void main( String args[] ) 11 { 12 int sum = 0; 13 14 // sum even integers from 2 through 100 15 for ( int number = 2; number <= 100; number += 2 ) 16 sum += number; 17 18 // display results 19 JOptionPane.showMessageDialog( null, "The sum is " + sum, 20 "Sum Even Integers from 2 to 100", 21 JOptionPane.INFORMATION_MESSAGE ); 22 23 System.exit( 0 ); // terminate the application 24 25 } // end method main 26 27 } // end class Sum increment number by 2 each iteration Sum.java
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有