How to list even numbers between 1 and 100?

 
 

Share on Google+Share on Google+

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

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









Ads

 
Advertisement null

Ads