Hello can someone show me how to write or have java print for me the even numbers ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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