正在加载图片...
3 while gradevalue !=-1 ) Average2.java 34 loop until gradeCounter /add gradevalue to totar 36 total total gradevalue equals sentinel value (-1) 7 /add 1 to gradeCounter 39 gradeCounter gradeCounter +1; 0 41 /prompt for input and read grade from user 2 input JOptionPane.showInputDialoa( 43 "Enter Integer Grade,-1 4 Format numbers to nearest /convert grade from a str hundredth 46 gradevalue Integer.parseInt(input ) 7 48 9 /Termination phase 50 DecimalFormat twoDigits new DecimalFormat("0.00"); 5 52 if gradecounter !=0 ) 53 average =(double)total gradeCounter; 54 5 /display average of exam grades 56 JOptionPane.showMessageDialog(null, 57 "Class average is "twoDigits.format(average ) 58 "Class Average",JOptionPane.INFORMATION MESSAGE ) 59 60 else JOptionPane.showMessageDialog(null, 62 "No grades were entered","class Average", 63 JOptionPane.INFORMATION MESSAGE ) 64 65 System.exit(0 ) /terminate application 66 ©2006计算机系杨厚群 All rights lefts reserved.©2006 计算机系 杨厚群 All rights & lefts reserved. 33 while ( gradeValue != -1 ) { 34 35 // add gradeValue to total 36 total = total + gradeValue; 37 38 // add 1 to gradeCounter 39 gradeCounter = gradeCounter + 1; 40 41 // prompt for input and read grade from user 42 input = JOptionPane.showInputDialog( 43 "Enter Integer Grade, -1 to Quit:" ); 44 45 // convert grade from a String to an integer 46 gradeValue = Integer.parseInt( input ); 47 } 48 49 // Termination phase 50 DecimalFormat twoDigits = new DecimalFormat( "0.00" ); 51 52 if ( gradeCounter != 0 ) { 53 average = (double) total / gradeCounter; 54 55 // display average of exam grades 56 JOptionPane.showMessageDialog( null, 57 "Class average is " + twoDigits.format( average ), 58 "Class Average", JOptionPane.INFORMATION_MESSAGE ); 59 } 60 else 61 JOptionPane.showMessageDialog( null, 62 "No grades were entered", "Class Average", 63 JOptionPane.INFORMATION_MESSAGE ); 64 65 System.exit( 0 ); // terminate application 66 Average2.java loop until gradeCounter equals sentinel value (-1) Format numbers to nearest hundredth
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有