Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet? System.out.print

Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet?

System.out.print ("Enter a number: "); Scanner in = new Scanner (System.in); String n1 = in.next (); System.out.print ("Enter another number: "); String n2 = in.next (); String result = n1 + n2; System.out.print (result);

107
4562
62
45 + 62

?????

?? 21 ?

Which of the following conditions is true only when the integer variables a, b, and c contain three different values?

(a != b) || (a != c) || (b != c)
!((a == b) && (b == c) && (a == c))
a != b != c
(a != b) && (a != c) && (b != c)

?????

?? 31 ?

Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?

int x; Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); x = in.nextInt();

if (x < 100) x = x + 5; if (x < 500) x = x - 2; if (x > 10) x++; else x--; System.out.println(x);

27
28
30
29

?????

?? 41 ?

What is the output of the code snippet given below?

for (int i = 0; i != 9; ) { System.out.print (" " + i); i = i + 2; }

No output
Invalid for statement
0 2 4 6 8
10 12 14 16 18 . (infinite loop)
0 2 4 6 8 10 12 14 . (infinite loop)

?????

?? 51 ?

How many times does the following code snippet display "Loop Execution"?

for (int i = 0; i < 10; i++) ; { System.out.println("Loop Execution") ; }

None
One time
Infinite loop
Ten times

?????

?? 61 ?

What does the output show when this loop executes and finally terminates?

for ( int i = 20 ; i >= 2 ; i = i - 6 ) { System.out.print ( i + ", " ); }

14, 8, 2
20, 19, 18, 17, . . . 4, 3, 2
20, 14, 8, 2
20, 14, 8, 2, 4

?????

?? 71 ?

Which of the following for loops is not valid?

for ( ; ; ) { . . . }
All are valid.
for (int i = 0, k = 1; ; i++) { . . . }
for (int i = 0) { . . . }
for (int i = 0; ; ) { . . . }

?????

?? 81 ?

Given the following code snippet, what should we change to have all 26 alphabetic characters in the string str?

String str = ""; for ( char c = 'A' ; c < 'Z' ; c++ ) { str = str + c; }

int c = 'A'
str = c + str;
Must change to use a do ... while loop
c <= 'Z'

?????

?? 91 ?

Insert a statement that will correctly terminate this loop when the end of input is reached.

boolean done = false; while (!done) { String input = in.next(); if (input.equalsIgnoreCase("Q")) { __________ } else { double x = Double.parseDouble(input); data.add(x); } }

done = 1;
exit;
done = true;
System.exit(0);
stop;
done = false;

?????

?? 101 ?

How many times will the output line be printed in the following code snippet?

for (int num2 = 1; num2 <= 3; num2++) { for (int num1 = 0; num1 <= 2; num1++) { System.out.println ( "" + num2 + " " + num1 ); } }

12 times
6 times
3 times
9 times

?????

?? 111 ?

Consider the following line of code for calling a method named methodX where data is an integer and varData is an double variable.

methodX (data, varData );

Which one of the following method headers is valid for methodX?

None are correct.
public static void methodX ( double list, int data)
public static void methodX ( double list, double data)
public static void methodX ( String list, int data)
public static void methodX ( int varData, double data)

?????

?? 121 ?

The non-static methods of a class are called the ____ methods of the class.

update
instance
frozen
permanent

?????

?? 131 ?

Which of the following is an example of a local identifier in the following code?

01: public class scopeRule 02: { 03: static double intRate = 0.055; 04: static String name; 05: static int t;

06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }

13: public static int first(int x, int y) 14: { 15: int t; 16: }

17: public static double salary; 18: }

name (Line 4)
t (Line 15)
salary (Line 17)
intRate (Line 3)

?????

?? 141 ?

Which of the following identifiers in the following code are usable in method first?

01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private static String name; 05: private int t;

06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }

13: public static int first(int x, int y) 14: { 15: int t; 16: }

17: public double salary; 18: }

Only salary (Line 17)
Both intRate (Line 3) and salary (Line 17)
Only intRate (Line 3)
first (Line 8)
name (Line 4)

?????

?? 151 ?

Which of the following identifiers in the following code are usable in another class?

01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private static String name; 05: private int t;

06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }

13: public static int first(int x, int y) 14: { 15: int t; 16: }

17: public double salary; 18: }

first (Line 13)
salary (Line 17)
Both intRate (Line 3) and salary (Line 17)
intRate (Line 3)

?????

?? 161 ?

In the method first, the programmer wishes to update the value stored in the variable intRate (Line 3). Which of the following is correct?

01: public class scopeRule 02: { 03: private double intRate = 0.055; 04: private String name; 05: private static int t;

06: public static int main(String[] args) 07: { 08: int first; 09: double u, t; 10: String str; 11: //. . . 12: }

13: public static int first(int x, int y) 14: { 15: double intRate; 16: intRate = x * y; 17: }

18: public double salary; 19: }

The code is correct. Nothing needs to be done.
Update it in the method main (Line 6)
Rename the variable on Line 15 to something else.
Write another non-static method to do so.

?????

?? 171 ?

Consider the following class definition.

public class Cylinder extends Object { private double height;

public Cylinder (double radius, double h) { super(radius); height = h; } public double getRadius() { return super.getRadius(); }

public String toString() { return (getRadius() + " " + height); }

public double surfaceArea() { return 2 * 3.14 * getRadius() * height; }

public double volume() { return 3.14 * getRadius() * getRadius() * height; } }

Suppose that you have the following declaration.

Cylinder cyl = new Cylinder(1.5, 10);

Which of the following statements are valid in Java?

System.out.print(cyl.surfaceArea);
cylinder.print();
cyl.volume();
cyl.surfaceArea();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions