Advertisement
psi_mmobile

Untitled

Jul 5th, 2022
694
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None
  1. import java.util.Scanner;
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.        Scanner scanner = new Scanner(System.in);
  5.         int num = Integer.parseInt(scanner.nextLine());
  6.         int sum = 0;
  7.         int startNumber = 1;
  8.         for (int i = 0; i < num; i++) {
  9.             System.out.println(startNumber);
  10.             sum+=startNumber;
  11.             startNumber+=2;
  12.         }
  13.         System.out.printf("Sum: %d",sum);
  14.     }
  15. }
Advertisement
RAW Paste Data Copied
Advertisement