Skip to main content

Posts

Showing posts with the label Write a Java program to print all odd number between 1 to 100.

ads1

5. Write a Java program to print all odd number between 1 to 100.

5. Write a Java program to print all odd number between 1 to 100. Static class loop5 { 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 loop5 { 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 :-

ads2