Advertisement
veronikaaa86

asd

May 18th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. public class P13RefactorSumOfOddNumbers {
  2. public static void main(String[] args) {
  3. Scanner scanner = new Scanner(System.in);
  4.  
  5. int n = Integer.parseInt(scanner.nextLine());
  6. int sum = 0;
  7. for (int i = 0; i < n; i++) {
  8. System.out.println(2 * i + 1);
  9. sum += 2 * i + 1;
  10. }
  11. System.out.printf("Sum: %d%n", sum);
  12.  
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement