Wednesday 22 May 2013

FINDING EVEN NUMBERS WITHIN A GIVEN RANGE USING CONTINUE STATEMENT IN JAVA


This program gives all the even numbers within a given range inputted by the user. This program is in Java and is a good program for those who are beginners in Java. This program illustrates the use of continue keyword. It also helps the beginners to get acquainted with the nextInt() function of the Scanner class that is specifically used to prompt the user to input an integer.

Source Code:-
/*******************************************************************************/
import java.util.Scanner;

//PROGRAM TO ILLUSTRATE THE USE OF CONTINUE KEYWORD
//PROGRAM TO FIND ALL THE EVEN NUMBERS BETWEEN A GIVEN RANGE.
public class continuekeyword {
public static void main(String[] args)
{
Scanner s=new Scanner (System.in);

System.out.println("ENTER THE LOWER LIMIT OF RANGE : ");
int a=s.nextInt();

System.out.println("ENTER THE UPPER LIMIT OF RANGE : ");
int b=s.nextInt();
for(int i=a;i<=b;i++)
{
if(i%2!=0)
continue;
System.out.println("i = "+i);

}
}
}
/********************************************************************************/

No comments:

Post a Comment