Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

How to list even numbers between 1 and 100?

Ads

 
 

Share on Google+Share on Google+

Java Coder
How to list even numbers between 1 and 100?
1 Answer(s)      2 months and 8 days ago
Posted in : Java Beginners

Hi,

I Java to check if a number is even?

How to list even numbers between 1 and 100?

Thanks

Ads
View Answers

April 16, 2017 at 5:08 PM


Hi,

If number is divisible by 2 then its even number.

Suppose you have a variable i then you can use following code for finding if the number is even:

if(i%2==0 ){
//Number is even
}

You can use the for loop and print all the numbers between 1 and 100

for (int i=1;i <=num ; i++){
  if(i%2==0 ){
  System.out.print(i+",");
  }

Check complete example at Write a program to list all even numbers between two numbers.

Thanks


Ads









Related Tutorials/Questions & Answers:
Advertisements