SHARE
TWEET

Untitled

a guest May 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumOdd {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int sum = 0;
  13.  
  14.         for (int i = 1; i <= n; i++) {
  15.             if (i % 2 != 0) {
  16.                 System.out.printf("%n%d", i);
  17.                 sum += i;
  18.             }
  19.         }
  20.         System.out.printf("%nSum: %d", sum);
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top