Write a program to display only even numbers number and ignoring the odd numbers from a range given by the user. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Write a program to display only even numbers number and ignoring the odd numbers from a range given by the user.

programs

19th Feb 2017, 11:54 AM
jatin
jatin - avatar
7 Answers
+ 4
import java.util.Scanner; public class Number { public static void main(String[] args) { int startFrom; int finishTo; Scanner keyboard=new Scanner(System.in); do { System.out.print("Insert the range (start from) :"); startFrom=keyboard.nextInt(); } while(startFrom<0); do { System.out.print("Insert the range (finish to) :"); finishTo=keyboard.nextInt(); } while(finishTo<startFrom); for(int i=startFrom; i<=finishTo; i++) { if(i%2==0) System.out.println(i); } }
19th Feb 2017, 1:15 PM
Antares
19th Feb 2017, 2:25 PM
Akshata
Akshata - avatar
+ 1
thanks akshata
19th Feb 2017, 2:26 PM
jatin
jatin - avatar
0
in loop. .for odd numbers use continue keyword to skip these loops and print even numbers.
19th Feb 2017, 12:38 PM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
0
can you do sir
19th Feb 2017, 12:39 PM
jatin
jatin - avatar
0
do you use whatsapp
19th Feb 2017, 2:28 PM
jatin
jatin - avatar
0
if I remember correctly every binary instruction has a parity bit that is on an 8-bit instruction of Zeros and one's 7 of the instruction added to the parity bit must be an even number so if an odd number is detected the computer knows there is an error without needing to understand what an error is so the first 7 digits are the instruction and if they add to 47 the parity bit would be one to make 48 but if they add to 48 then the parity bits would be 0 that's how computer checks for errors please correct me if I'm wrong
20th Feb 2017, 7:30 PM
Carl H von Ohlen
Carl H von Ohlen - avatar