Advertisement
thotfrnk

number2.java

Nov 11th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. //class work.
  2.  
  3. public class numberTwo {
  4.     public static void main(String[] args) {
  5.         /*
  6.         * (2) Write Java Programs using WHILE loops for each of the following:
  7.         * (a) Print all the numbers from 20 to 0.
  8.          */
  9.  
  10.         int v = 20, k = 0;
  11.  
  12.         while ( v >= 0) {
  13.             System.out.printf("%d\n", v);
  14.  
  15.             v--;
  16.         }
  17.  
  18.         //(b) Print all ODD numbers from 0 to 50.
  19.  
  20.         while (k <= 50) {
  21.  
  22.             if(k % 2 != 0) {
  23.  
  24.                 System.out.println("Odd numbers from 0 to 50 are: " +k);
  25.             }
  26.  
  27.             k++;
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement