Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- int count = 1;
- int a = 1;
- int sum = 0;
- while (count <= num) {
- if (a % 2 != 0) {
- System.out.println(a);
- sum = sum + a;
- count++;
- }
- a++;
- }
- System.out.printf("Sum: %d", sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement