Advertisement
Shavit

P. 169 Ex. 7.14

Nov 3rd, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6.  
  7. public class OddRandom {
  8.  
  9.     public static void main(String[] args)
  10.    
  11.     {
  12.         Scanner in = new Scanner (System.in);
  13.         Random r = new Random ();
  14.        
  15.         int num;
  16.         int sum = 0;
  17.        
  18.         for (int i = 0; i < 10; i++)
  19.         {
  20.             num = 100 + r.nextInt(900);
  21.             if (num % 2 == 1)
  22.                 sum = sum + (int)num;
  23.         }
  24.        
  25.         System.out.printf("The sum of the odd numbers generated is %d.", sum);
  26.        
  27.         in.close();
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement