Programming Test #3

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

Will the following program terminate? int balance 10; while (true) if(balance < 9) break; balance = balance - 9;

yes

which of the following expression results in 43.37? a. (int) (45.378 * 100) / 100 b. (int) (45.378 * 100) / 100.0 . c. (int) (45.378 * 100 /.100) d. (int) (45.378) * 100 / 100.0

(int) (45.378 * 100) / 100.0

Assume x = 4.and y = 5, which of the following is true? a . ! ( x == •4•) ",.y '!= 5 b. x != 4 ^ y == 5 c. x == 5 ^ y == 4 d. x != 5 ^ y != 4

...

The extension name of a Java bytecode ,file is

.class

What is the .possible output from System.out .println( (int) (1 + Math .random () * 4))?

1 ,2 ,3 ,4

Math.pow(9, 1 / 2) returns _____

1.0

3. Show the output of the follow1ing code. Hint, this is a nested loop public class Test { public static void main (String[] args) { int i = l; while (i <= 4 ){ int num = 1; for (int j = 1; j <= i; j ++) System .out .print(num + "bb"); num *= 3; } System .out .println() ; i++; } } }

1bb 1bb3bb 1bb3bb9bb 1bb3bb9bb27bb

5. What is x after evaluating: x = (2 > 3) ? 2 : 3;

3

Show the output of the following code : public class Test3{ public static void main(String [] args){ for (int i = 0; i < 5; i++) System .out.print( (i + 4 ) + " " ) ; } }

4 , 5 , 6 , 7 , 8

How many times is the System.out.println() statement executed? for(int i = 0; i < 10; i++) for(int j = 0; j < i; j++) System.out.println(i * j);

45

What is the output for y? int y = 0 ; for (int i =0; i<10; ++i ){ y += i; } System.out.println(y) ;

45

What is the value of sum after the following loop terminates? int sum = 0 ; int item = 0; do { item++; sum += item; if(sum > 4) break; }while (item < 5) ;

6

What is the output of this program? public class Test3 public static void main(String [) args) { int sum = O; int number = O; while (number <= 10) { number++; if (number % 2 == 0 || number % 3 == 0) continue; sum += number; } System .out .println( "The sum is " + sum); } }

The sum is 24

If you .forget to put a closing quotation mark on a string, what kind of error will be raised?

a compilation error

20. Which of the follow1ing loop (s) print (s) "Test3" 10 times? a. for (int count = 1; count <= 10; count++) System.out.println("Test3") ; } b. for (int count = 0; count < 10; count++) System.out.println( "Test3"); } c. for (int count = 1; count < 10; count++) { System .out.println( "Test3") ; } d. for (int count = 0; count <= 10; count++) System .out .println ("Test3 "); }

a. for (int count = 1; count <= 10; count++) System.out.println("Test3") ; } b. for (int count = 0; count < 10; count++) System.out.println( "Test3"); }

Which of the following expressions will yield 0.5? a. 1 /2 b. 1.0 / 2 c. (double) (1 / 2) d. (double) 1 /2 e. 1 / 2.0

b. 1.0 / 2 d. (double) 1 /2 e. 1 / 2.0

Analyze the following code : public class Test3{ public static void main (String srgs[)) { int i = 0; for(i = o; i < 10; i++); System.out.println(i + 4); a . The program has a compile error because of the semicolon (;) on the for loop line. .b. The program compiles despite the semicolon (;) on the for loop line, and displays 4 . c. The for loop in this program is same as for (i= 0; i < 10; i++) { }; System .out.println( i + 4); d. The program compiles despite the semicolon (;) on the for loop line, and displays 14.

c. The for loop in this program is same as for (i= 0; i < 10; i++) { }; System .out.println( i + 4); d. The program compiles despite the semicolon (;) on the for loop line, and displays 14.

What is x after the following statements are executed? int x = 2; int y = 1; x *= y + 1;

x = 4

17. What is the printout after the following loop terminates? int number = 25; int i; boolean isPrime = true; for (i = 2; i < number; i++) if (number % i == 0) { isPrime = false; break; } } System.out .println( "i is " + i + " isPrime is "+ isPrime);

i is 5 isPrime is false

What is the number of iterations in the following loop? for (int i = 1; i < n; i++) { //iteration

n-1

4. Show the output of the following code: (write the output next to each println statement if the println statement is executed in the program) . public class Test { public static void main(String( ) args) { int x = 943; int number = 4; System .out .println (3 + 4 * 2 > 2 * 9); if (number % 3 == 0) System.out.println( 3 * number); else System.out .println( 4 * number); System.out.println(x / 100); System.out .println(x % 100); System.out.println(x + " is " + ((x % 2 != 0) ? "even" : "odd")); } }

public class Test { public static void main(String( ) args) { int x = 943; int number = 4; System .out .println (3 + 4 * 2 > 2 * 9); --> false if (number % 3 == 0) System.out.println( 3 * number); else System.out .println( 4 * number); --> 16 System.out.println(x / 100);--> 9 System.out .println(x % 100);--> 43 System.out.println(x + " is " + ((x % 2 != 0) ? "even" : "odd")); -->943 } }


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

Chapter 13 The Spinal Cord, Spinal Nerves, and Somatic Reflexes

View Set

FIN Midterm #2 - Sample Questions

View Set

ECON 1000 Online - Chapter 6 - Ohio University

View Set

Anatomy & Phys Chapter 7 The Nervous System Review notes

View Set

NUR 322 - exam 4 practice questions - ATI, prepU, etc

View Set