Concepts & Methods Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Consider the following method. public static void doSomething() { System.out.println("Something has been done"); } Each of the following statements appears in a method in the same class as doSomething. Which of the following statements are valid uses of the method doSomething? I. doSomething(); II. String output = doSomething(); III. System.out.println(doSomething());

I only

What will be displayed? for(int k = 0; k < 20; k+=2) { if( k%3 == 1) { System.out.print( k + " , "); } } I. 4 , 16 II. 4 , 10 , 16 III. 0 , 6 , 12 , 18 IV. 1, 4 , 7 , 10 , 13 , 16 , 19

II. 4, 10, 16

Consider the following statement: int num = /* expression */; Which of the following replacements for /* expression */ creates in num a random integer from 2 to 50, including 2 and 50? (A) (int)(Math.random() * 50) - 2 (B) (int)(Math.random() * 49) - 2 (C) (int)(Math.random() * 49) + 2 (D) (int)(Math.random() * 50) + 2 (E) (int)(Math.random() * 48) + 2

(C) (int)(Math.random() * 49) + 2

Consider the following method, which is intended to calculate and return the expression ( x + y ) 2 | a − b | . public double calculate(double x, double y, double a, double b) { return /* missing code */; } Which of the following can replace /* missing code */ so that the method works as intended? (A) Math.sqrt(x ^ 2, y ^ 2, a - b) (B) Math.sqrt((x + y) ^ 2) / Math.abs(a, b) (C) Math.sqrt((x + y) ^ 2 / Math.abs(a - b)) (D) Math.sqrt(Math.pow(x + y, 2) / Math.abs(a, b)) (E) Math.sqrt(Math.pow(x + y, 2) / Math.abs(a - b))

(E) Math.sqrt(Math.pow(x + y, 2) / Math.abs(a - b))

The Student class has been defined to store and manipulate grades for an individual student. The following methods have been defined for the class. /* Returns the sum of all of the student's grades */ public double sumOfGrades() { /* implementation not shown */ } /* Returns the total number of grades the student has received */ public int numberOfGrades() { /* implementation not shown */ } /* Returns the lowest grade the student has received */ public double lowestGrade() { /* implementation not shown */ } Which of the following statements, if located in a method in the Student class, will determine the average of all of the student's grades except for the lowest grade and store the result in the double variable newAverage ? (A ) newAverage = sumOfGrades() / numberOfGrades() - 1; (B) newAverage = sumOfGrades() / (numberOfGrades() - 1); (C) newAverage = sumOfGrades() - lowestGrade() / (numberOfGrades() - 1); (D) newAverage = (sumOfGrades() - lowestGrade()) / numberOfGrades() - 1; (E) newAverage = (sumOfGrades() - lowestGrade()) / (numberOfGrades() - 1);

(E) newAverage = (sumOfGrades() - lowestGrade()) / (numberOfGrades() - 1);

Which of the following symbols is used to block non-executable statements, in Java? a) // b) {} c) /* */ d) (* *)

a) // c) /* */

Consider the following code segment. String oldStr = "ABCDEF"; String newStr = oldStr.substring(1, 3) + oldStr.substring(4); System.out.println(newStr); What is printed as a result of executing the code segment? a) BCEF b) ABCD c) ABCDEF d) BCDE e) BCDEF

a) BCEF

A variable is a: a) memory location whose value can change while the program is running b) memory location whose value cannot change while the program is running c) blueprint of an object d) set of values or domain

a) memory location whose value can change while the program is running

Evaluate 25 % 5 / 3 a) 1 b) 0 c) 0.4175 d) 1.67

b) 0

Consider the following code segment. String temp = "comp"; System.out.print(temp.substring(0) + " " + temp.substring(1) + " " + temp.substring(2) + " " + temp.substring(3)); What is printed when the code segment is executed? a) comp b) comp omp mp p c) comp com co c d) c o m p e) comp comp comp comp

b) comp omp mp p

From which group of statements if the statement System.out.println("Welcome to the world of programming"); an example? a) selection b) sequence c) iteration d) looping

b) sequence

The following code segment is supposed to calculate and display the sum of 1 + 2 + ... + 20: int count = 0, sum = 0; while (count < 20) { sum += count; } System.out.println (sum); What is the result of the lines of code shown above? a) the sum display will be correct b) there will be no output b/c the program goes into an infinite loop c) the output will be "20" d) the sum display will be 20 too small

b) there will be no output b/c the program goes into an infinite loop

Consider the following methods, which appear in the same class. public void slope(int x1, int y1, int x2, int y2) { int xChange = x2 - x1; int yChange = y2 - y1; printFraction(yChange, xChange); } public void printFraction(int numerator, int denominator) { System.out.print(numerator + "/" + denominator); } Assume that the method call slope(1, 2, 5, 10) appears in a method in the same class. What is printed as a result of the method call? a) 4/8 b) 2/1 c) 1/5 d) 8/4 e) 5/1

d) 8/4

Consider the following method. public double myMethod(int a, boolean b) { /* implementation not shown */ } Which of the following lines of code, if located in a method in the same class as myMethod, will compile without error? a) double result = myMethod(true, 10); b) double result = myMethod(2.5, true); c) int result = myMethod(2.5, true); d) double result = myMethod(0, false); e) int result = myMethod(2, false);

d) double result = myMethod(0, false);

The programming language Java is described as a: a) assembly language b) low level language c) machine language d) high level language

d) high level language

the term used to express the rules of a language is: a) interpreter b) semantics c) library d) syntax

d) syntax


Kaugnay na mga set ng pag-aaral

NCLEX 10000 ENDOCRINE AND METABOLIC

View Set

Principles of Management: Ch. 10 Quiz

View Set