BPJ 01-03 Quiz

  1. Write a statement to print out the following:

     Doc Mo said, "I hope you studied."
    
  2. How do you run a main method that is in another class?

public class Q2 {  // in file "Q2.java"
 public static void main() {   /* do something */ }
}
public class Main { // in file "Main.java"
 public static void main(String[] args) {
  // What goes here?
 }
}
  1. Comment on the legality of each of these lines of code:

    1. double alpha = 314;
    2. int beta = 28.18;
    3. String gamma = "alpha = "+alpha;
    4. double delta = 3_141_592 * 10^-6;
  2. Declare but do not initialize a String variable called q5.

  3. Write two different kinds of comments.

    1. Type I
    2. Type II
  4. Given String s = "U do well", what is s.substring(1,4)? Put your answer in quotes.

  5. Type the the output from the following code exactly.

String k = "Alan Turing";
int n = k.length();
System.out.print(n);
System.out.println(k.substring(8));