Advertisement
psi_mmobile

Untitled

Jul 5th, 2022
679
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 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 = 1; i <=num; i++) {
  9.             sum+=startNumber;
  10.             startNumber+=2;
  11.         }
  12.         System.out.printf("Sum: %d",sum);
  13.     }
  14. }
Advertisement
RAW Paste Data Copied
Advertisement