Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class work.
- public class numberTwo {
- public static void main(String[] args) {
- /*
- * (2) Write Java Programs using WHILE loops for each of the following:
- * (a) Print all the numbers from 20 to 0.
- */
- int v = 20, k = 0;
- while ( v >= 0) {
- System.out.printf("%d\n", v);
- v--;
- }
- //(b) Print all ODD numbers from 0 to 50.
- while (k <= 50) {
- if(k % 2 != 0) {
- System.out.println("Odd numbers from 0 to 50 are: " +k);
- }
- k++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement