+ 4
Hello can someone show me how to write or have java print for me the even numbers ?
13 Answers
+ 4
Makseem
The number divisible by 2 is even number. So do this use modulus operator (%)
if(number % 2 == 0) //even
+ 3
Display Even Numbers Example java
public class DisplayEvenNumbersExample1 Â
{Â Â
public static void main(String args[])  Â
{Â Â
int number=100; Â
System.out.print("List of even numbers from 1 to "+number+": "); Â
for (int i=1; i<=number; i++)  Â
{Â Â
//logic to check if the number is even or not Â
//if i%2 is equal to zero, the number is even Â
if (i%2==0)  Â
{Â Â
System.out.print(i + " "); Â
}Â Â
}Â Â
}Â Â
}Â Â
+ 3
Martin Taylor ok bro and thanks for the advice.
+ 2
Martin Taylor can you explain it plz because I can't understand how it works(the bitwise operation solution). Tnx
+ 2
Martin Taylor wow I understand this, but I never cared about the properties of the bit notation of odd and even numbers. This is surprising. From now, for even or odd number checking I'm using your method =)
+ 2
Arun Jamson when i clicked run it gave an error why and also what the letter. i stands for
+ 1
Martin Taylor why did you put ! And where did the Parentheses come from? I want to understand that will you show me please or help me
+ 1
Makseem In the following example, I have declared a variable named number and initialized it with 100 (the limit to print the even number). We have used a for loop that executes up to 100 times and for each iteration of i the if statement checks the number is even or not. After printing each even number, the value if i is increased by 1.
0
Will you please show me this in a java ?
0
I am very new i am trying to learn thank you