Advertisement
bobo_bobkata

Untitled

Jan 24th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1.  Scanner scanner = new Scanner(System.in);
  2.  
  3.         int num = Integer.parseInt(scanner.nextLine());
  4.         int count = 1;
  5.         int a = 1;
  6.         int sum = 0;
  7.  
  8.         while (count <= num) {
  9.             if (a % 2 != 0) {
  10.                 System.out.println(a);
  11.                 sum = sum + a;
  12.                 count++;
  13.             }
  14.             a++;
  15.         }
  16.         System.out.printf("Sum: %d", sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement