-bash-4.1$ cat Exam.java
class Exam {
  public static String middle(String str) {
    if (str.length() == 0) {
      return str;
    } else if (str.length() % 2 == 0) {
      int i = (str.length() - 1) / 2;
      return str.substring( i, i + 2 );
    } else {
      int i = str.length() / 2;
      return str.substring( i, i + 1 );
    }
  }
  public static void two() {
    int x = 3, y = 5, count = 0;
    while (x != y && count < 6) {
      x = x + y;
      y = x - y;
      x = x - y;
      System.out.println( x + " " + y );
      count += 1;
    }
  }
  public static int fibo(int n) {
    int fold1 = 0, fold2 = 1, fnew = fold1 + fold2;
    if (n == 0) fnew = fold1;
    else if (n == 1) fnew = fold2;
    else for (int i = 2; i <= n; i++) {
           fnew = fold1 + fold2;
           fold1 = fold2;
           fold2 = fnew;
         }
    return fnew;
  }
  public static void four() {
    int x = 3, y = 5;
    int b = x++ + y++ - ++y - ++x;
         // 3 and x becomes 4
               // 5 and y becomes 6
                       // 7 as y just became 7
                             // 5 as x just became 5
    // so b becomes 3 + 5 - 7 - 5 = -4
    System.out.println( x + " " + y + " " + b );
             // prints  5         7        -4
  }
  public static void five(String letter) {
    if (letter.length() != 1 || ! "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".contains(letter))
      System.out.println("Invalid input: " + letter);
    else if ("AEIOUaeiou".contains(letter))
      System.out.println( letter + " is a vowel.");
    else
      System.out.println( letter + " is a consonant.");
  }
  public static void main(String[] args) {
    System.out.println(Exam.middle(args[0]));
    Exam.two(); // infinite loop if count removed
    System.out.println( Exam.fibo( Integer.parseInt( args[1] ) ) );
    Exam.four();
    Exam.five(args[2]);
  }
}
-bash-4.1$ javac Exam.java
-bash-4.1$ java Exam what 6 a
ha
5 3
3 5
5 3
3 5
5 3
3 5
8
5 7 -4
a is a vowel.
-bash-4.1$ java Exam who 9 x
h
5 3
3 5
5 3
3 5
5 3
3 5
34
5 7 -4
x is a consonant.
-bash-4.1$ java Exam at 11 why
at
5 3
3 5
5 3
3 5
5 3
3 5
89
5 7 -4
Invalid input: why
-bash-4.1$ java Exam a 0 9
a
5 3
3 5
5 3
3 5
5 3
3 5
0
5 7 -4
Invalid input: 9
-bash-4.1$ java Exam "" 3 U

5 3
3 5
5 3
3 5
5 3
3 5
2
5 7 -4
U is a vowel.
-bash-4.1$