Here are the simple java programs that we did in class on Tuesday March 29.

helloWorld.java

public class helloWorld
{
   public static void main(String args[]) {
      System.out.println("Hello world!");
   }
}
printArgs.java
public class printArgs
{
   public static void main(String args[]) {

      System.out.print("args:");

      for (int i = 0 ; i < args.length ; i++)
         System.out.print(" " + args[i]);

      System.out.println();
   }
}
power.java
public class power
{
   public static void main(String args[]) {

      // System.err.println("There are " + args.length + " arguments");

      if (args.length < 2)

         // Error message if not enough arguments.

         System.err.println("usage: java power A B");
      else {

         // Convert arguments from strings to doubles.

	 double t = Double.parseDouble(args[0]);

	 double p = Double.parseDouble(args[1]);

	 System.out.println(Math.pow(t, p));
      }
   }
}
sort.java
public class sort
{
  public static void main(String args[]) {

     // It's convenient to have the number of args as an int variable.

     int n = args.length;

     // Loop through all the slots in the array

     for (int i = 0 ; i < n - 1 ; i++)

        // Find the smallest one that's left

        for (int j = i + 1 ; j < n ; j++)

	    // string1.compareTo(string2) returns -1, 0, or 1.

            if (args[i].compareTo(args[j]) > 0) {

	       String tmp = args[i];
	       args[i] = args[j];
	       args[j] = tmp;
	    }

     // When done, print out the sorted arguments

     for (int i = 0 ; i < n ; i++)
        System.out.print(args[i] + " ");

     System.out.println();
  }
}
fibonacci.java
public class fibonacci
{
   public static void main(String args[]) {
      if (args.length < 1)

         System.err.println("usage: java fibonacci N");

      else {
         int n = Integer.parseInt(args[0]);

	 for (int i = 0 ; i <= n ; i++)
	    System.out.print(i + ":" + fib(i) + " ");

	 System.out.println();
      }
   }

   // Example of a recursive function

   static int fib(int n) {
      if (n < 2)
         return 1;
      else
         return fib(n - 1) + fib(n - 2);
   }
}