Hi,
I Java to check if a number is even?
How to list even numbers between 1 and 100?
Thanks
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