+ 3

Display n even numbers (not upto n)

guys i know this is a dumb question from me so could anyone tell me how to do that? and plz consider this one too i have a loop which runs like upto 100000 even numbers but i want it to stop at the number specified by the user for example: i am trying to print binary even numbers under 100000 so consider user input is 2 so only 2 binary numbers shd be displayed rather than going all way to 100000... thanks in advance

1st Feb 2018, 7:35 PM
Suhail Pappu
Suhail Pappu - avatar
6 Answers
+ 15
for(int a=2,b=0;b<n;b++) System.out.println(a+=2);
2nd Feb 2018, 8:31 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
i thought u want even numbers after seeing one of the answers here 😅
2nd Feb 2018, 2:21 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
I think it should be like this : I used JS. var n = prompt ("enter a number"); for (i=0;i<100000;i++){ if(i==n){ break ; } if(i%2==0){ console.log(i); } }
1st Feb 2018, 8:04 PM
Mazin Ayash
Mazin Ayash - avatar
+ 1
gaurav i didnt get you? well here is my code to make things more clearer https://code.sololearn.com/cMZPX3dLGhOY/?ref=app
2nd Feb 2018, 2:18 PM
Suhail Pappu
Suhail Pappu - avatar
+ 1
lol that was just an internal part but if u see the code i would understand my actual problem haha the problem is "a number shd be even as well as it shd contain 2 active bits i.e no of 1's" so i tried to get all the satisfying numbers below 'm' so instead of printing all I want to print only 'n' numbers which is specified by the user ..if n=2 then first two of the satisfying Condition numbers shd be displayed
2nd Feb 2018, 2:25 PM
Suhail Pappu
Suhail Pappu - avatar
+ 1
lol i always do silly mistakes and make it a big mess out of it.. haha well i got it gaurav ..and guys thanks for replying :) I'll update my correct code :)
2nd Feb 2018, 2:53 PM
Suhail Pappu
Suhail Pappu - avatar