Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.

Thursday, August 5, 2010

Sum the odd numbers and the even numbers from 1 to an upperbound


/*Sum the odd numbers and the even numbers from 1 to an upperbound*/
public class OddAndEvenSum 
{  // Save as "OddAndEvenSum.java"
   public static void main(String[] args) 
   {
      int sumOdd  = 0;    // for accumulating odd numbers, init to 0
      int sumEven = 0;    // for accumulating even numbers, init to 0
      int upperbound = 10;
      for (int number = 1; number <= upperbound; number++) 
      {
         if (number % 2 == 0) {  // even
            sumEven = sumEven + number;
         } else {                // odd
            sumOdd = sumOdd + number;
         }
      } 
      // print the result
      System.out.println("The sum of odd numbers is " + sumOdd);
      System.out.println("The sum of even numbers is " + sumEven);
      System.out.println("The difference is " + (sumOdd - sumEven));
   }
}

ADS

How to earn online

How to earn online:
Step - 1 :
signup for PayPal, to recieve your online earning
click here:
https://www.paypal.com/in/mrb/pal=CZ7224TZBMCBL
step - 2 : Singup these 4 sites & earn & enjoy! Read site to know how to earn.
1. trekpay
Earn up to $0.02 (2 cents) per click.
http://www.trekpay.com/?ref=34690
2. neobux
Earn up to $0.02 (2 cents) per click.
Click here:
http://www.neobux.com/?r=Moneyearner786

AddMe

Bookmark and Share