Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fundamentals.basics;
- import java.util.Scanner;
- public class RefactorSumOddNumbers {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- int sum = 0;
- for (int i = 0; i < n; i++) {
- System.out.println(2 * i + 1);
- sum += 2 * i + 1;
- }
- System.out.printf("Sum: %d%n", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement