Answered step by step
Verified Expert Solution
Link Copied!

Question

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

4562

45 + 62

62

107

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

a != b != c

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

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

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

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

29

28

30

27

What is the output of the code snippet given below?

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

Invalid for statement

0 2 4 6 8

0 2 4 6 8 10 12 14 . (infinite loop)

10 12 14 16 18 . (infinite loop)

No output

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

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

One time

Ten times

Infinite loop

None

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, 14, 8, 2

20, 14, 8, 2, 4

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

Which of the following for loops is not valid?

for (int i = 0; ; ) { . . . }

All are valid.

for (int i = 0) { . . . }

for ( ; ; ) { . . . }

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

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

c <= 'Z'

Must change to use a do ... while loop

int c = 'A'

str = c + str;

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 = false;

System.exit(0);

done = 1;

stop;

exit;

done = true;

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

9 times

3 times

Identify the correct statement for defining an integer array named numarray of ten elements.

int numarray [ 10 ];

int [ 10 ] numarray;

int [ ] numarray = new int [ 10 ];

int [ ] numarray = new int [ 9 ];

Complete the following code with the correct enhanced for loop so it iterates over the array without using an index variable.

String[] arr = { "abc", "def", "ghi", "jkl" };

___________________

{ System.out.print(str); }

for ( str : String arr )

for ( str [ ] : arr )

for ( String str : arr )

for ( arr [ ] : str )

What is the result of the following code where values is a one-dimensional array?

for (double element : values) { element = 0; }

The elements of the array values are initialized to zero.

Invalid for statement.

The first element of the array values is initialized to zero.

The array is not modified.

The elements of the array element are initialized to zero.

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

methodX ( listData, varData );

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

public static void methodX ( int list, int data)

public static void methodX ( int list [ ] , int data)

public static void methodX ( int [ 10 ] list, int data)

None are correct.

public static void methodX ( int [ ] list, int data)

Assume the variable numbers has been declared to be an array that has at least one element. Which is the following represents the last element in numbers?

numbers [ numbers.length() ]

numbers.length

numbers [ numbers.length ]

numbers [ numbers.length 1 ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago