Posted By

joswald on 11/19/10


Tagged

loop exercise objectsFirst


Versions (?)

Exercise 4.51


 / Published in: Java
 

  1. public class Exercise0451
  2. {
  3. public void printGreater( double marks, double mean )
  4. {
  5. for( index = 0; index <= marks.length; index++ )
  6. {
  7. if( marks[index] > mean )
  8. {
  9. System.out.println( marks[index] );
  10. }
  11. }
  12. }
  13.  
  14. /**
  15. * Print all the values in the marks array that are
  16. * greater than mean
  17. * @param marks An array of mark values
  18. * @param mean The mean mark.
  19. */
  20. public static void main( String[] args )
  21. {
  22. double[] arrayOfDoubles = {1.2, 3.7, 0.9, 5.6, 2.3}
  23.  
  24. Exercise0451 e = new Exercise0451();
  25.  
  26. e.printGreater( arrayOfDoubles, 2.7 );
  27. }
  28. }

Report this snippet   <

You need to login to post a comment.