Commit db1c530c authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch1] Final chapter exercises

parent b4ec8362
Loading
Loading
Loading
Loading
+29 −0
Changes for src/main/java/ch1/PoolPuzzleOne.java: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch1;

class PoolPuzzleOne {
  public static void main(String[] args) {
    int x = 0;

    while (x < 4) {
      System.out.print("a");
      if (x < 1) {
        System.out.print(" ");
      }
      System.out.print("n");

      if (x > 1) {
        System.out.print(" oyster");
        x = x + 2;
      }
      if (x == 1) {
        System.out.print("noys");
      }
      if (x < 1) {
        System.out.print("oise");
      }
      System.out.println();

      x = x + 1;
    }
  }
}
+26 −0
Changes for src/main/java/ch1/Shuffle1.java: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch1;

class Shuffle1 {
  public static void main(String[] args) {

    int x = 3;
    while (x > 0) {

      if (x > 2) {
        System.out.print("a");
      }

      x = x - 1;
      System.out.print("-");

      if (x == 2) {
        System.out.print("b c");
      }

      if (x == 1) {
        System.out.print("d");
        x = x - 1;
      }
    }
  }
}
 No newline at end of file
+41 −0
Changes for src/main/java/ch1/Test.java: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch1;

class Test {
  public static void main(String[] args) {
    int x = 0;
    int y = 0;
    while (x < 5) {
      //
      // candidate code goes here
      //

      System.out.print(x + "" + y + " ");
      x = x + 1;
    }
  }
}  


//        y = x - y;      00 11 21 32 42
//
//        y = y + x;      00 11 23 36 410
//
//        y = y + 2;      02 14 25 36 47
//        if( y > 4 ) {
//        y = y - 1;
//        }
//
//        x = x + 1;      11 34 59
//        y = y + x;
//
//        if ( y < 5 ) {  02 14 36 48
//        x = x + 1;
//        if ( y < 3 ) {
//        x = x - 1;
//        }
//        }
//        y = y + 2;