HarrJ

Day 11 loops a

Jul 3rd, 2023 (edited)
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. public class Day11B {
  2.     public static void main(String[] args) {
  3.         int i = 0;
  4.        
  5.         while (i < 10) {
  6.             System.out.println("while: "+i);
  7.             i++;
  8.         }
  9.        
  10.         i = 50;
  11.         while (i >= 7) {            
  12.             System.out.println("b: "+i);
  13.             i -= 3;
  14.         }
  15.        
  16.         i = 0;
  17.         do {
  18.             System.out.println("do While: " + i);
  19.             i++;
  20.         } while (i < 10);
  21.     }
  22. }
  23.  
  24. //------------------------------------
  25.  
  26. public class Day11C {
  27.     public static void main(String[] args) {
  28.         int ref = 9;
  29.         int j;
  30.         int k = ref;
  31.        
  32.         while (k > 0) {
  33.             j = ref;
  34.             while (j > 0) {
  35.                 System.out.print(j);
  36.                 j--;
  37.             }
  38.             System.out.println(k);
  39.             k--;
  40.         }
  41.  
  42.         System.out.println("----------------------------");
  43.        
  44.         k = ref;
  45.         while (k > 0) {
  46.             j = ref;
  47.             while (j > 0) {
  48.                 if (k == 1 || k == ref) {
  49.                     System.out.print("&");
  50.                 } else {
  51.                     if (j == 1 || j == ref) {
  52.                         System.out.print("&");
  53.                     } else {
  54.                         System.out.print(" ");
  55.                     }
  56.                 }
  57.                 j--;
  58.             }
  59.             System.out.println("");
  60.             k--;
  61.         }
  62.     }
  63. }
  64.  
  65. //------------------
  66. public class Day11F {
  67.     public static void main(String[] args) {
  68.         String[] txtArray1 = {
  69.             "car"
  70.             ,"fish"
  71.             ,"boat"
  72.             ,"ship"
  73.             ,"crab"
  74.         };
  75.        
  76.         System.out.println("array length: " + txtArray1.length);
  77.         System.out.println("txtArray1 contents(descending)");
  78.         for (int i = txtArray1.length - 1; i >= 0; i--) {
  79.             System.out.println(i + ". " + txtArray1[i]);
  80.         }
  81.         System.out.println("txtArray1 contents(ascending)");
  82.         for (int i = 0; i < txtArray1.length; i++) {
  83.             System.out.println((i + 1) + ": " + txtArray1[i]);
  84.         }
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment