Wednesday, September 1, 2010

While Loop get even numbers

hello programmers.... i want to share to you how to create a program that get the even numbers using modulo operator and while loop.

here is the program:

import java.util.Scanner;

public class evennumbers
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int x=1;
System.out.print("How many numbers you want to print:");
num=input.nextInt();

while(x<=num)
{
if(x%2==0)
{
System.out.println(x);
}
x++;
}

}
}

No comments:

Post a Comment