Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.     public static void main (String[] args) throws java.lang.Exception
  11.     {
  12.         Scanner keyboard = new Scanner (System.in);
  13.         System.out.println("Enter a positive integer and that number of odd integers will be totaled and displayed: ");
  14.         int n;
  15.         int sum = 0;
  16.         n = keyboard.nextInt();
  17.         for (int i = 1, j = 0; j < n; i += 2, j++)
  18.             sum += i;
  19.         System.out.print("The total is " + sum);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement