Chapter 6 Flashcards
Arguments to methods always appear within __________.
parentheses
You should fill in the blank in the following code with \_\_\_\_\_\_\_\_\_\_\_\_\_\_. public class Test { public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5); System.out.print("The grade is "); printGrade(59.5); } public static \_\_\_\_\_\_\_\_\_\_ printGrade(double score) { if (score >= 90.0) { System.out.println('A'); } else if (score >= 80.0) { System.out.println('B'); } else if (score >= 70.0) { System.out.println('C'); } else if (score >= 60.0) { System.out.println('D'); } else { System.out.println('F'); } } }
void
Consider the following incomplete code: public class Test { public static void main(String[] args) { System.out.println(f(5)); }
public static int f(int number) { // Missing body } } The missing method body should be \_\_\_\_\_\_\_\_.
return number;
Which of the following should be defined as a void method?
Write a method that prints integers from 1 to 100.
Which of the following is the best for generating random integer 0 or 1?
(int)(Math.random() + 0.5)
Suppose your method does not return any value, which of the following keywords can be used as a return type?
void
Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.
a stack
_________ is a simple but incomplete version of a method.
stub
Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long l) { System.out.println("int, long"); return n; } public static long xMethod(long n, long l) { System.out.println("long, long"); return n; } }
The program displays int, long followed by 5.
(int)(Math.random() * (65535 + 1)) returns a random number __________.
between 0 and 65535
Does the method call in the following method cause compile errors?
public static void main(String[] args) {
Math.pow(2, 4);
}
no
Does the return statement in the following method cause compile errors? public static void main(String[] args) { int max = 0; if (max != 0) System.out.println(max); else return; }
no
You should fill in the blank in the following code with \_\_\_\_\_\_\_\_\_\_\_\_\_\_. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static \_\_\_\_\_\_\_\_\_ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; } }
char
All Java applications must have a method __________.
public static void main(String[] args)
The signature of a method consists of ____________.
method name and parameter list