public class EvenNum {
public static void main(String[] args)
{
//FOR LOOP
System.out.println("------------ using for loop ------------");
for (int a=2; a<=50; a++)
{
System.out.print(a+" ");
a=a+1;
};
//WHILE LOOP
System.out.println(" ");
System.out.println("------------ using while loop ------------");
int a = 2;
while(a<=50)
{
System.out.print(a+" ");
a=a+2;
};
//DO..WHILE LOOP
System.out.println(" ");
System.out.println("------------ using do...while loop ------------");
int x = 2;
do
{
System.out.print(x+" ");
x=x+2;
}
while(x<=50);
}
}
No comments:
Post a Comment