4. Write a Java program to print all even numbers between 1 to 100. - using while loop.
Sol :-
(Static)
class loop4
{
public static void main(String args[])
{
int i=1,j=20;
while(i<=j)
{
if(i%2==0)
System.out.println(i);
i++;
}
}
}
Output :-
Dynamic
import java.util.*;
class loop4
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int i,j;
System.out.println("Enter the Starting number :- ");
i=in.nextInt();
System.out.println("Enter the Ending number :- ");
j=in.nextInt();
while(i<=j)
{
if(i%2==0)
System.out.println(i);
i++;
}
}
}
Output :-