Self Check Ch3 Essay

Submitted By LordN
Words: 618
Pages: 3

3.1 Which of the following is the correct syntax for a method header with parameters? (The order of the answer choices is randomly shuffled each time.)

1.
2.
3.
4.
5.

public static void example(int x, int y) { public static void example(int x,y) { public static (int x, int y) example() { public static void example(x: int, y: int) { public static void example(x, y) {

3.2 What output is produced by the following program? public class MysteryNums { public static void main(String[] args) { int x = 15; sentence(x, 42); int y = x - 5; sentence(y, x + y);
}
public static void sentence(int num1, int num2) {
System.out.println(num1 + " " + num2);
}
}
15 42
10 25

3.7
Given the following program: public class MysteryWho { public static void main(String[] args) {
String whom = "her";
String who = "him";
String it = "who";
String he = "it";
String she = "whom"; sentence(he, she, it); sentence(she, he, who); sentence(who, she, who); sentence(it, "stu", "boo");

sentence(it, whom, who);
}
public static void sentence(String she, String who, String whom) {
System.out.println(who + " and " + whom + " like " + she);
}
}
Write the output of each of the following calls.
Top of Form

sentence(he, she, it); whom and who like it

sentence(she, he, who); it and him like whom

sentence(who, she, who);
Whom and him like him

sentence(it, "stu", "boo"); stu and boo like who

sentence(it, whom, who);

her and him like who

3.8
What output is produced by the following program? public class MysteryTouch { public static void main(String[] args) {
String head = "shoulders";
String knees = "toes";
String elbow = "head";
String eye = "eyes and ears";
String ear = "eye"; touch(ear, elbow); touch(elbow, ear); touch(head, "elbow"); touch(eye, eye); touch(knees, "Toes"); touch(head, "knees " + knees);
}
public static void touch(String elbow, String ear) {
System.out.println("touch your " + elbow + " to your " + ear);
}
}
Top of Form

touch(ear, elbow); touch your eye to your head

touch(elbow, ear); touch your head to your eye

touch(head, "elbow"); touch your shoulders to your elbow touch(eye, eye); touch your eyes and ears to your eyes and ears

touch(knees, "Toes"); touch your toes to your Toes

touch(head, "knees " + knees); touch your shoulders to your knees toes

Bottom of Form

3.10
Write a method called printStrings that accepts a
String
and a number of repetitions as parameters and