Here's a short program to demonstrate the use of the keyword "continue" in Java. It prints all the odd numbers up to n, as taken from the user.
Java Program :
class continue_
{
static void cal(int n)
{
System.out.print("The odd numbers up to '"+n+"' are : ");
for(int i=1;i<=n;i++)
{
if(i%2==0)
continue;
else
System.out.print(i+" ");
}
}
}
Java Program :
class continue_
{
static void cal(int n)
{
System.out.print("The odd numbers up to '"+n+"' are : ");
for(int i=1;i<=n;i++)
{
if(i%2==0)
continue;
else
System.out.print(i+" ");
}
}
}
No comments:
Post a Comment