CS 305j - Discussion Section Assignment #1



1. Write some Java statements that produce the following output.

In Java, the "coolest" programming language, we have two character sequences called escape sequences.

Double quotes escape sequence: \"
Tab escape sequence: \t
Newline escape sequence: \n
Backslash escape sequence: \\

2. Write a complete Java program that produces the following output. Your program must be structured, and you must use static methods to eliminate redundancy.

++xx+xx++
+               +
+               +
+               +
++xx+xx++
      +  +
      +  +
++xx+xx++
+               +
+               +
+               +
++xx+xx++
++xx+xx++
+               +
+               +
+               +
++xx+xx++
      +  +
      +  +
      +  +
      +  +

3. What is the output from this program?

public class WhatsUp
{
    public static void main(String[] args)
    {
          System.out.println("Begin main");
          one();
          System.out.println("main 1");
          two();
          System.out.println("main 2");
          three();
          System.out.println("End main");
    }

    public static void one()
    {
          System.out.println("1");
    }

    public static void two()
    {
          one();
          System.out.println("22");
    }

    public static void three()
    {
          two();
          System.out.println("333");
          two();
          one();
    }
}

4. Write an algorithm to make a peanut butter, jelly and banana sandwich. What steps does someone need to follow to make a sandwich? Structure the instructions and remove any redundancies.