Sponsered Links
Categories
Sponsered Links

Find Even and Odd numbers

 

Through the above code, we are finding the even and odd numbers from 1 to 20.

class OddEvenNumbers{
public static void main (String args[]){
        String evenNo = "";
        String oddNo = "";
        for (int i = 1; i <=100; i++){          
                if (i % 2 == 0) {                                      
                evenNo += i + " ";
                }
                else{
                    oddNo +=i+ " ";
                }
  }
       System.out.println("Even Numbers between 1 to 20 are: "+evenNo);
       System.out.println("Odd Numbers between 1 to 20 are: "+oddNo);
}
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved