Hello can someone show me how to write or have java print for me the even numbers ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Hello can someone show me how to write or have java print for me the even numbers ?

14th Oct 2021, 2:38 AM
Makseem
Makseem - avatar
10 Answers
+ 4
Makseem The number divisible by 2 is even number. So do this use modulus operator (%) if(number % 2 == 0) //even
14th Oct 2021, 2:40 AM
A͢J
A͢J - avatar
+ 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 + " ");   }   }   }   }  
14th Oct 2021, 1:24 PM
Arun Jamson
Arun Jamson - avatar
+ 3
Martin Taylor ok bro and thanks for the advice.
15th Oct 2021, 7:34 AM
Arun Jamson
Arun Jamson - avatar
+ 2
Martin Taylor can you explain it plz because I can't understand how it works(the bitwise operation solution). Tnx
14th Oct 2021, 2:59 AM
Rishi
Rishi - avatar
+ 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 =)
14th Oct 2021, 10:51 AM
Rishi
Rishi - avatar
+ 2
Arun Jamson when i clicked run it gave an error why and also what the letter. i stands for
14th Oct 2021, 2:07 PM
Makseem
Makseem - avatar
+ 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
14th Oct 2021, 3:03 AM
Makseem
Makseem - avatar
+ 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.
14th Oct 2021, 2:18 PM
Arun Jamson
Arun Jamson - avatar
0
Will you please show me this in a java ?
14th Oct 2021, 2:41 AM
Makseem
Makseem - avatar
0
I am very new i am trying to learn thank you
14th Oct 2021, 2:41 AM
Makseem
Makseem - avatar