chapter 3: parameters: practice it: ap cs

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What output is produced by the following program? public class Weird { public static void main(String[] args) { int number = 8; halfTheFun(11); halfTheFun(2 - 3 + 2 * 8); halfTheFun(number); System.out.println("number = " + number); } public static void halfTheFun(int number) { number = number / 2; for (int count = 1; count <= number; count++) { System.out.print(count + " "); } System.out.println(); } }

1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 number = 8

What output is produced by the following program? public class Odds { public static void main(String[] args) { printOdds(3); printOdds(17 / 2); int x = 25; printOdds(37 - x + 1); } public static void printOdds(int n) { for (int i = 1; i <= n; i++) { int odd = 2 * i - 1; System.out.print(odd + " "); } System.out.println(); } }

1 3 5 1 3 5 7 9 11 13 15 1 3 5 7 9 11 13 15 17 19 21 23 25

Math.abs(-1.6) Math.abs(2 + -4) Math.pow(6, 2) Math.pow(5 / 2, 6) Math.ceil(9.1) Math.ceil(115.8) Math.max(7, 4) Math.min(8, 3 + 2) Math.min(-2, -5) Math.sqrt(64) Math.sqrt(76 + 45) 100 + Math.log10(100) 13 + Math.abs(-7) - Math.pow(2, 3) + 5 Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3)) 7 - 2 + Math.log10(1000) + Math.log(Math.pow(Math.E, 5)) Math.max(18 - 5 + Math.random(), Math.ceil(4.6 * 3))

1.6 2 36.0 64.0 10.0 116.0 7 5 -5 8.0 11.0 102.0 17.0 20.0 13.0 14.0 basic rules: power is double ceiling and floor are double max and min are int square root is double

Assuming that the following variables have been declared, // index 0123456789012345 String str1 = "Frodo Baggins"; String str2 = "Gandalf the GRAY"; Evaluate the following expressions. Make sure to give a value of the appropriate type (such as including quotes around a String or apostrophes around a char). str1.length() str1.charAt(7) str2.charAt(0) str1.indexOf("o") str2.toUpperCase() str1.toLowerCase().indexOf("B") str1.substring(4) str2.substring(3, 14) str2.replace("a", "oo") str2.replace("gray", "white") "str1".replace("r", "range")

13 'a' 'G' 2 "GANDALF THE GRAY" -1 "o Baggins" "dalf the GR" "Goondoolf the GRAY" "Gandalf the GRAY" "strange1"

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

Given the following code fragment, describe what will happen when the user types each of the following values. If the code will read the value successfully, describe the value that will be stored in the variable money. If it will not, write exception . (Make sure to write a value of the proper type, such as 12.0 rather than 12 for a double.) Scanner console = new Scanner(System.in); System.out.print("How much money do you have? "); double money = console.nextDouble(); 34.50 6 $25.00 million 100*5 600x000 none 645

34.5 6.0 exception exception exception exception exception 645.0

Given the following code, what indexes must be passed to the substring method to produce the new String with the value "SCORE"? What indexes to substring produce "fouryears"? // index 012345678901234567890123456789 String quote = "Four score and seven years ago"; String expr1 = quote.substring(a, b).toUpperCase(); // "SCORE" String expr2 = quote.toLowerCase().substring(c, d) + quote.substring(e, f); // "fouryears" a b c d e f

5 10 0 4 21 26

In a program reading user input by means of a Scanner, the user types the line of input below, exactly as shown, including that same spacing. What is each token returned by the Scanner? Hello there. 1+2 is 3 and 1.5 squared is 2.25! token # 1 token # 2 token # 3 token # 4 token # 5 token # 6 token # 7 token # 8 token # 9 token # 10

Hello there. 1+2 is 3 and 1.5 squared is 2.25!

What output is produced by the following code? String first = "James"; String last = "Kirk"; String middle = "T."; System.out.println(last); System.out.println("My name is " + first); System.out.println(first + " " + last); System.out.println(last + ", " + first + " " + middle); System.out.println(middle + " is for Tiberius");

Kirk My name is James James Kirk Kirk, James T. T. is for Tiberius

Assuming that the following variables have been declared, String str1 = "Q.E.D."; String str2 = "Arcturan Megadonkey"; String str3 = "Sirius Cybernetics Corporation"; Evaluate the following expressions. Make sure to give a value of the appropriate type (such as including quotes around a String). str1.length() str2.length() str1.toLowerCase() str2.toUpperCase() str1.substring(2, 4) str2.substring(10, 14) str1.indexOf("D") str1.indexOf(".") str2.indexOf("donkey") str3.indexOf("X") str2 + str3.charAt(17) str3.substring(9, str3.indexOf("e")) str3.substring(7, 12) str2.toLowerCase().substring(9, 13) + str3.substring(18, str3.length() - 7)

REMEMBER QUOTES WHEN NEEDED 6 19 "q.e.d." "ARCTURAN MEGADONKEY" "E." "egad" 4 1 13 -1 "Arcturan Megadonkeys" "b" "Cyber" "mega Corp"

Write code that prompts the user for a phrase and a number of times to repeat it, then prints the phrase the phrase that many times. Here is an example dialogue with the user: What is your phrase? His name is Robert Paulson How many times should I repeat it? 3 His name is Robert Paulson His name is Robert Paulson His name is Robert Paulson

Scanner console = new Scanner(System.in); System.out.print("What is your phrase? "); String phrase = console.nextLine(); System.out.print("How many times should I repeat it? "); int times = console.nextInt(); for (int i = 1; i <= times; i++) { System.out.println(phrase); }

Write code to read an integer from the user, then print that number multipliedby 2. You may assume that the user types a valid integer. A sample run of the code would produce the following: Type an integer: 4 4 times 2 = 8

Scanner console= new Scanner (System.in); System.out.print("Type an integer: "); int input=console.nextInt(); int answer=input*2; System.out.println(input+ " times 2 " + "= " + answer);

public class MysteryReturn { public static void main(String[] args) { int x = 1; int y = 2; int z = 3; z = mystery(x, z, y); // Statement 1 System.out.println(x + " " + y + " " + z); // Statement 2 x = mystery(z, z, x); // Statement 3 System.out.println(x + " " + y + " " + z); // Statement 4 y = mystery(y, y, z); // Statement 5 System.out.println(x + " " + y + " " + z); // Statement 6 } public static int mystery(int z, int x, int y) { z--; x = 2 * y + z; y = x - 1; System.out.println(y + " " + z); return x; } } Write the output of each statement.

Statement 1 3 0 Statement 2 1 2 4 Statement 3 4 3 Statement 4 5 2 4 Statement 5 8 1 Statement 6 5 9 4

public class MysteryNumbers { public static void main(String[] args) { String one = "two"; String two = "three"; String three = "1"; int number = 20; sentence(one, two, 3); sentence(two, three, 14); sentence(three, three, number + 1); sentence(three, two, 1); sentence("eight", three, number / 2); } public static void sentence(String three, String one, int number) { System.out.println(one + " times " + three + " = " + (number * 2)); } }

Write the output of each of the following calls. sentence(one, two, 3); three times two = 6 sentence(two, three, 14); 1 times three = 28 sentence(three, three, number + 1); 1 times 1 = 42 sentence(three, two, 1); three times 1 = 2 sentence("eight", three, number / 2); 1 times eight = 20

double grade = 2.7; Math.round(grade); // a) grade = grade = Math.round(grade); // b) grade = double min = Math.min(grade, Math.floor(2.9)); // c) min = double x = Math.pow(2, 4); // d) x = x = Math.sqrt(64); // e) x = int count = 25; Math.sqrt(count); // f) count = count = (int) Math.sqrt(count); // g) count = int a = Math.abs(Math.min(-1, -3)); // h) a =

a) grade = 2.7 b) grade = 3.0 c) min = 2.0 d) x = 16.0 e) x = 8.0 f) count = 25 g) count = 5 h) a = 3

public class MysterySoda { public static void main(String[] args) { String soda = "coke"; String pop = "pepsi"; String coke = "pop"; String pepsi = "soda"; String say = pop; carbonated(coke, soda, pop); carbonated(pop, pepsi, pepsi); carbonated("pop", pop, "koolaid"); carbonated(say, "say", pop); } public static void carbonated(String coke, String soda, String pop) { System.out.println("say " + soda + " not " + pop + " or " + coke); } }

carbonated(coke, soda, pop); say coke not pepsi or pop carbonated(pop, pepsi, pepsi); say soda not soda or pepsi carbonated("pop", pop, "koolaid"); say pepsi not koolaid or pop carbonated(say, "say", pop); say say not pepsi or pepsi

The System.out.println command works on many different types of values, including ints and doubles. What is the term for such a method?

overload

The following program contains 9 errors. Correct the errors and submit a working version of the program. The corrected version of the program should produce the following output: x = 10.01 and y = 8.0 x = 10.01 and y = 867.5309 The value from main is: 867.5309 z = 5 public class Oops3 { public static void main() { double bubble = 867.5309; double x = 10.01; printer(double x, double y); printer(x); printer("barack", "obama"); System.out.println("z = " + z); } public static void printer(x, y double) { int z = 5; System.out.println("x = " + double x + " and y = " + y); System.out.println("The value from main is: " + bubble); } }

public class Oops3 { public static void main (String[]args) { double y = 8.0; int z = 5; double x = 10.01; printer ( x, y); y=867.5309; double bubble=y; printer(x,y); System.out.println("The value from main is: " + bubble); System.out.println("z = " + z); } public static void printer(double x,double y) { System.out.println("x = " + x + " and y = " + y); } } line 5: cannot use variable y without declaring and initializing it line 5: cannot declare the type of y in the method call line 6: cannot call printer without the correct number of parameters (2, in this case) line 7: cannot call printer by passing the correct type of parameters (double, in this case) line 8: cannot refer to the variable z: it is in scope inside printer, not main line 11: must provide a type for x line 11: must provide a variable name for the second parameter line 12: must refer to the parameters using the exact same spelling line 13: cannot refer to variables in main that were not passed into printer as a parameter

Consider the following program. Modify the given SumNumbers code to use a Scanner to prompt the user for the values of low and high. The following is a sample execution in which the user asks for the sum of the values 1 through 10: public class SumNumbers { public static void main(String[] args) { int low = 1; int high = 1000; int sum = 0; for (int i = low; i <= high; i++) { sum += i; } System.out.println("sum = " + sum); } } low? 1 high? 10 sum = 55

public class SumNumbers { public static void main(String[] args) { Scanner console= new Scanner (System.in); System.out.print("low? "); int low=console.nextInt(); System.out.print("high? "); int high=console.nextInt(); int sum=0; for (int i = low; i <= high; i++) { sum+= i; } System.out.println("sum = " + sum); } }

The following program contains several errors. Correct the errors and submit a working version of the program. The corrected version of the program should produce the following output: Body temp in C is: 37.0 public class Temperature { public static void main(String[] args) { double tempf = 98.6; double tempc = 0.0; ftoc(tempf, tempc); System.out.println("Body temp in C is: " + tempc); } // converts Fahrenheit temperatures to Celsius public static void ftoc(double tempf, double tempc) { tempc = (tempf - 32) * 5 / 9; } }

public class Temperature { public static void main(String[] args) { double tempf = 98.6; double tempc = 0.0; ftoc(tempf, tempc); } // converts Fahrenheit temperatures to Celsius public static void ftoc(double tempf, double tempc) { tempc = (tempf - 32) * 5 / 9; System.out.println("Body temp in C is: " + tempc); } } have to move the print line because if not it will not update the values

Write a method padString that accepts two parameters: a String and an integer representing a length. The method should pad the parameter string with spaces until its length is the given length. For example, padString("hello", 8) should return " hello". (This sort of method is useful when trying to print output that lines up horizontally.) If the string's length is already at least as long as the length parameter, your method should return the original string. For example, padString("congratulations", 10) would return "congratulations".

public static String padString(String word, int totalLength) { int len=word.length(); if (totalLength <= len) return(word); for (int i=0; i<(totalLength-len); i++) { word = " " + word; } return(word); }

Write a method named area that accepts the radius of a circle as a parameter and returns the area of a circle with that radius. For example, the call area(2.0) should return 12.566370614359172. You may assume that the radius is non-negative.

public static double area(double radius){ return (Math.PI*radius*radius); }

Write a method called cylinderSurfaceArea that accepts a radius and height (both real numbers) as parameters and returns the surface area of a cylinder with those dimensions. For example, the call cylinderSurfaceArea(3.0, 4.5) should return 141.3716694115407. The formula for the surface area of a cylinder with radius r and height h is the following: surface area = 2πr2 + 2πrh

public static double cylinderSurfaceArea(double radius, double height){ return Math.PI*2*(radius*radius)+2*Math.PI*radius*height; }

Write a method called distance that accepts four integer coordinates x1, y1, x2, and y2 as parameters and computes the distance between points (x1, y1) and (x2, y2) on the Cartesian plane. The equation for the distance is: distance equation For example, the call of distance(1, 0, 4, 4) would return 5.0 and the call of distance(10, 2, 3, 5) would return 7.615773105863909.

public static double distance (int x1, int y1, int x2, int y2){ return (Math.sqrt(Math.pow( x2-x1,2)+ Math.pow( y2-y1,2))); }

Write a method named pay that accepts a real number for a TA's salary and an integer for the number of hours the TA worked this week, and returns how much money to pay the TA. For example, the call pay(5.50, 6) should return 33.0. The TA should receive "overtime" pay of 1 ½ normal salary for any hours above 8. For example, the call pay(4.00, 11) should return (4.00 * 8) + (6.00 * 3) or 50.0.

public static double pay(double pay, int hours){ int overtime=hours-8; double salary =hours*pay; if (overtime>0){ salary=salary+.5*pay*overtime; } return(salary); }

Write a method called scientific that accepts two real numbers as parameters for a base and an exponent and computes the base times 10 to the exponent, as seen in scientific notation. For example, the call of scientific(6.23, 5.0) would return 623000.0 and the call of scientific(1.9, -2.0) would return 0.019.

public static double scientific (double base, double exponet){ return base* Math.pow(10, exponet); }

Write a method called sphereVolume that accepts a radius (a real number) as a parameter and returns the volume of a sphere with that radius. For example, the call sphereVolume(2.0) should return 33.510321638291124. The formula for the volume of a sphere with radius r is the following: volume = 4/3 π r3

public static double sphereVolume(double radius){ return 4.0/3*Math.PI*(radius*radius*radius); }

Write a method called triangleArea that accepts the three side lengths of a triangle (all real numbers) as parameters and returns the area of a triangle with those side lengths. For example, the call triangleArea(8, 5.2, 7.1) should return 18.151176098258745. To compute the area, use Heron's formula, which states that the area of a triangle whose three sides have lengths a, b, and c, is the following. The formula is based on the computed value s, a length equal to half the perimeter of the triangle: area = √ (s (s-a)(s-b)(s-c)) where s = (a + b + c) / 2

public static double triangleArea(double a, double b, double c){ double s=(a+b+c)/2; return Math.sqrt(s*(s-a)*(s-b)*(s-c)); }

Write a method called countQuarters that takes an int representing a number of cents as a parameter and returns the number of quarter coins represented by that many cents. Don?t count any whole dollars, because those would be dispensed as dollar bills. For example, countQuarters(64) would return 2, because 2 quarters make 50 cents, with 14 extra left over. A call of countQuarters(1278) would return 3, because after the 12 dollars are taken out, 3 quarters remain in the 78 cents left.

public static int countQuarters(int cents) { return cents % 100 / 25; }

Write a method called largerAbsVal that takes two integers as parameters and returns the larger of the two absolute values. A call of largerAbsVal(11, 2) would return 11, and a call of largerAbsVal(4, -5) would return 5.

public static int largerAbsVal (int x, int y){ return Math.max(Math.abs(x), Math.abs(y)); }

Write a method largestAbsVal that accepts three integers as parameters and returns the largest of their three absolute values. For example, a call of largestAbsVal(7, -2, -11) would return 11, and a call of largestAbsVal(-4, 5, 2) would return 5.

public static int largestAbsVal (int x, int y, int z){ int ans= Math.max(Math.abs(x), Math.abs(y)); return Math.max(Math.abs(z), ans); }

Write a method named lastDigit that returns the last digit of an integer. For example, lastDigit(3572) should return 2. It should work for negative numbers as well. For example, lastDigit(-947) should return 7. Call Value Returned lastDigit(3572) 2 lastDigit(-947) 7 lastDigit(6) 6 lastDigit(35) 5 lastDigit(123456) 6 (Hint: This is a short method. You may not use a String to solve this problem.)

public static int lastDigit(int x){ return (Math.abs(x) %10) ; }

Write a method called min that takes three integers as parameters and returns the smallest of the three values, such that a call of min(3, -2, 7) would return -2, and a call of min(19, 27, 6) would return 6. Use Math.min to write your solution.

public static int min(int n1, int n2, int n3){ return Math.min(n1, Math.min(n2, n3)); }

Which of the following is the correct syntax for a method header with parameters? public static void example(x, y) { public static (int x, int y) example() { public static void example(x: int, y: int) { public static void example(int x, int y) { public static void example(int x,y) {

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

Write a method called inputBirthday that accepts a Scanner for the console as a parameter and prompts the user to enter a month, day, and year of birth, then prints the birthdate in a suitable format. Here is an example dialogue with the user: On what day of the month were you born? 8 What is the name of the month in which you were born? May During what year were you born? 1981 You were born on May 8, 1981. You're mighty old!

public static void inputBirthday(Scanner console){ System.out.print("On what day of the month were you born? "); int day=console.nextInt(); System.out.print("What is the name of the month in which you were born? "); String month=console.next(); System.out.print("During what year were you born? "); int year=console.nextInt(); System.out.println("You were born on "+month+" "+day+", "+year+"."+" You're mighty old!"); }

Write a method named printGrid that accepts two integer parameters rows and cols. The output is a comma-separated grid of numbers where the first parameter (rows) represents the number of rows of the grid and the second parameter (cols) represents the number of columns. The numbers count up from 1 to (rows x cols). The output are displayed in column-major order, meaning that the numbers shown increase sequentially down each column and wrap to the top of the next column to the right once the bottom of the current column is reached. Assume that rows and cols are greater than 0. Here are some example calls to your method and their expected results: Call: printGrid(3, 6); printGrid(5, 3); printGrid(4, 1); printGrid(1, 3); Output: 1, 4, 7, 10, 13, 16 2, 5, 8, 11, 14, 17 3, 6, 9, 12, 15, 18 1, 6, 11 2, 7, 12 3, 8, 13 4, 9, 14 5, 10, 15 1 2 3 4 1, 2, 3

public static void printGrid(int rows, int cols) { for(int lines=1;lines<=rows;lines++){ int x=lines; for(int number=lines;number<cols+lines-1;number++){ System.out.print(x+", "); x+=rows; } System.out.print(x); System.out.println(); } }

Write a method called printNumbers that accepts a maximum number as a parameter and prints each number from 1 up to that maximum, inclusive, boxed by square brackets. For example, consider the following calls: printNumbers(15); printNumbers(5); These calls should produce the following output: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [1] [2] [3] [4] [5] You may assume that the value passed to printNumbers is 1 or greater.

public static void printNumbers(int n) { for(int i=1; i<=n;i++){ System.out.print("[" + i + "] "); } }

Write a method called printPowersOf2 that accepts a maximum number as an argument and prints each power of 2 from 20 (1) up to that maximum power, inclusive. For example, consider the following calls: printPowersOf2(3); printPowersOf2(10); These calls should produce the following output: 1 2 4 8 1 2 4 8 16 32 64 128 256 512 1024

public static void printPowersOf2 (int n){ int ans =1; for (int i=0; i<= n; i++){ System.out.print(ans + " "); ans=ans*2; } System.out.println(); }

Write a method called printPowersOfN that accepts a base and an exponent as arguments and prints each power of the base from base0 (1) up to that maximum power, inclusive. For example, consider the following calls: printPowersOfN(4, 3); printPowersOfN(5, 6); printPowersOfN(-2, 8); These calls should produce the following output: 1 4 16 64 1 5 25 125 625 3125 15625 1 -2 4 -8 16 -32 64 -128 256 You may assume that the exponent passed to printPowersOfN has a value of 0 or greater. (The Math class may help you with this problem. If you use it, you may need to cast its results from double to int so that you don't see a .0 after each number in your output. Also, can you write this program without using the Math class?)

public static void printPowersOfN(int x, int y){ for (int i=0; i<=y;i++){ System.out.print((int)Math.pow(x, i)); System.out.print(" "); } }

Write a method called printReverse that accepts a String as its parameter and prints the characters in opposite order. For example, a call of printReverse("hello there!"); should print the following output: !ereht olleh If the empty string is passed, no output is produced. Your method should produce a complete line of output.

public static void printReverse(String phrase) { for (int i=phrase.length()-1; i>=0; i--) { System.out.print(phrase.charAt(i)); } }

Write a method called printSquare that takes in two integer parameters, a min and a max, and prints the numbers in the range from min to max inclusive in a square pattern. The square pattern is easier to understand by example than by explanation, so take a look at the sample method calls and their resulting console output in the table below. Each line of the square consists of a circular sequence of increasing integers between min and max. Each line prints a different permutation of this sequence. The first line begins with min, the second line begins with min + 1, and so on. When the sequence in any line reaches max, it wraps around back to min. You may assume the caller of the method will pass a min and a max parameter such that min is less than or equal to max. Call printSquare(1, 5); printSquare(3, 9); printSquare(0, 3); printSquare(5, 5); Output 12345 23451 34512 45123 51234 3456789 4567893 5678934 6789345 7893456 8934567 9345678 0123 1230 2301 3012 5

public static void printSquare(int min, int max) { for (int row=min;row<=max;row++){ for (int a=row; a<=max;a++){ System.out.print(a); } int c=min; for (int b=1;b<=row-min;b++){ System.out.print(c); c++; } System.out.println(); } }

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call: printStrings("abc", 5); will print the following output: abcabcabcabcabc

public static void printStrings(String s, int n) { for (int i = 1; i <= n; i++) { System.out.print(s); } System.out.println(); }

Write a method called processName that accepts a Scanner for the console as a parameter and that prompts the user to enter his or her full name, then prints the name in reverse order (i.e., last name, first name). You may assume that only a first and last name will be given. You should read the entire line of input at once with the Scanner and then break it apart as necessary. Here is a sample dialogue with the user: Please enter your full name: Sammy Jankis Your name in reverse order is Jankis, Sammy

public static void processName(Scanner console) { System.out.print("Please enter your full name: "); String name = console.nextLine(); String first=name.substring(0,name.indexOf(" ")); String last=name.substring(name.indexOf(" ")+1); System.out.println("Your name in reverse order is "+last+ ", "+ first); }

led quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form a x2 + b x + c = 0. The formula for solving a quadratic equation is: quadratic equation Here are some example equations and their roots: equation x2 - 7x + 12 x2 + 3x + 2 call quadratic(1, -7, 12); quadratic(1, 3, 2); output First root = 4.0 Second root = 3.0 First root = -1.0 Second root = -2.0 Your method should accept the coefficients a, b, and c as parameters and should print the roots of the equation. You may assume that the equation has two real roots, though mathematically this is not always the case. Also, there should be two roots, one the result of the addition, the other, the result of the subtraction. Print the root resulting from the addition first.

public static void quadratic (int a, int b, int c){ double x = Math.sqrt(b*b - 4* a* c); double y = (-b + x)/(2*a); double z = (-b - x)/(2*a); System.out.println("First root = " + y); System.out.println("Second root = " + z); }

Write a method called vertical that accepts a String as its parameter and prints each letter of the string on separate lines. For example, a call of vertical("hey now") should produce the following output: h e y n o w

public static void vertical(String phrase){ for (int i=0;i<phrase.length();i++){ System.out.println(phrase.substring(i,i+1)); } }

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); } }

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

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); } }

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


संबंधित स्टडी सेट्स

COM221: Ch. 10 Key Terms (unfinished)

View Set

History Chapter 2 Test Lesson 1-2

View Set

Chapter Exam - Homeowners (HO) Policies

View Set

Edit with the Docs app Make tweaks, leave comments, and share with others to edit at the same time. NO THANKSGET THE APP MODULE 01: Vocabulary Terms copy Read all directions while working at lab (T or F) Pick up broken glassware with your hands (T or F

View Set

Chapter 60: Introduction to the Musculoskeletal System

View Set