Advertisement
Guest User

MoMo's OddSum 1.0

a guest
Sep 26th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public class OddSum {
  2. /**
  3. Example output if user enters 10:
  4. Max?
  5. 1 + 3 + 5 + 7 + 9 = 25
  6. 25 = 9 + 7 + 5 + 3 + 1
  7.  
  8. Example output if user enters 11:
  9. Max?
  10. 1 + 3 + 5 + 7 + 9 + 11 = 36
  11. 36 = 11 + 9 + 7 + 5 + 3 + 1
  12.  
  13.  */
  14.  public static void main(String[] args) {
  15.      
  16.      int i;
  17.      int max;
  18.      int sum = 0;
  19.      TextIO.putln("Max?");
  20.      max = TextIO.getlnInt();
  21.      
  22.      for(i = 1; i <= max; i+=2)
  23.      {
  24.          TextIO.put(i);
  25.          sum += i;
  26.          if(i % 2 != 0){
  27.              
  28.          }
  29.            
  30.          
  31.      }
  32.      TextIO.put(i + " ");
  33.  
  34.   } // end of main method
  35. } // end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement