Question
30: What is the output of the following code snippet? public static void main(String[] args) { int num1 = 10; int num2 = 5; int
30:
What is the output of the following code snippet?
public static void main(String[] args)
{
int num1 = 10;
int num2 = 5;
int num3 = 200;
num3 = num3 % (num1 * num2);
System.out.println(num3);
}
Select one:
a. 0
b. 4
c. 10
d. 250
31:
Consider the following code snippet:
ArrayList
somedata.add(10.5);
What is the size of the array list somedata after the given code snippet is
executed?
Select one:
a. 0
b. 1
c. 10
d. 2
32:
How do you compute the length of the string str?
Select one:
a. length(str)
b. length.str
c. str.length
d. str.length()
33.
How do you compute the length of the string str?
Select one:
a. length(str)
b. length.str
c. str.length
d. str.length()
33.
Consider a situation where multiple if statements are combined into a chain to
evaluate a complex condition. Which of the following reserved words is used to
define the branch to be executed when none of the conditions are true?
Select one:
a. if
b. else if
c. else
d. All of the above items
34:
Consider the following code snippet:
int[][] numarray =
{
{ 3, 2, 3 },
{ 0, 0, 0 }
};
System.out.print(numarray[0][0]);
System.out.print(numarray[1][0]);
What is the output of the given code snippet?
Select one:
a. 00
b. 31
c. 30
d. 03
35:
Given the method below, what is the output of the method call is div(10)?
public static void div(int n)
{
if (n > 2)
{
div(n % 3);
}
System.out.print(n / 3 + " ");
}
Select one:
a. 0 10
b. 3
c. 0 3
d. 10
36:
Consider the following code snippet:
public static void main(String[] args)
{
ArrayList
names.add("John");
names.add("Jerry");
names.add("Janet");
ArrayList
}
public static ArrayList
{
ArrayList
for (int i = names.size() - 1; i >= 0; i--)
{
result.add(names.get(i));
}
return
}
Which statement is true after the main method is executed?
Select one:
a. names contains "Janet", "Jerry", "John" in this order
b. names contains "John", "Jerry", "Janet" in this order
c. reverse method has a bound error
37:
Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively,
what is the output of the following code snippet?
public static void main(String[] args)
{
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);
}
Select one:
a. 46
b. 4662
c. 107
d. 4562
38:
Every statement in Java must be terminated with
Select one:
a. the semi-colon character ;
b. a carriage return
c. System.out.println()
d. an escape sequence
39:
A Java "class" file
Select one:
a. contains Java source code
b. contains instructions to the Java virtual machine
c. is an internal file created by the Integrated Development Environment (IDE)
d. is the translation of the Java source code into C++
40:
How many times does the following loop run?
int i = 0;
int j = 1;
do
{
System.out.println("" + i + ";" + j);
i++;
if (i % 2 == 0)
{
j--;
}
}
while (j >= 1);
Select one:
a. 0 times
b. 1 times
c. 2 times
d. 4 times
41:
Consider a situation where you are buying books online. The bookseller charges
$19.95 as the price per book and $4.95 as the handling cost for up to three books.
For every book purchased in addition to three books, there is a handling charge of
$1.50. In addition, there is a 7 percent tax on the cost of the books but not on the
handlingCharges. Assuming that numBooks represents the number of books
you are purchasing, which of the following is the correct algorithm for calculating
the total cost of your purchase?
Select one:
a.
Total charge for books = 19.95 * numBooks
Tax on the books = numBooks * .7
if (books <= 3) then handlingCharges = 4.95
else handlingCharges = 1.50 * numBooks
Total cost of order = total charge for books + tax + handlin
gCharges
b.
Total charge for books = 19.95 * numBooks
Tax on the books = total charge for books * .07
if (books = 3) then handlingCharges = 4.95
else handlingCharges = 1.50 * numBooks
Total cost of order = total charge for books + tax + handlin
gCharges
c.
Total charge for books = 19.95 * numBooks
Tax on the books = numBooks * .07
if (books < 3) then handlingCharges = 4.95
else handlingCharges = 4.95 + 1.50 * (numBooks 3)
Total cost of order = total charge for books + tax + handlin
gCharges
d.
Total charge for books = 19.95 * numBooks
Tax on the books = total charge for books * .07
if (books <= 3) then handlingCharges = 4.95
else handlingCharges = 4.95 + 1.50 * (numBooks 3)
Total cost of order = total charge for books + tax + handlin
gCharges
42:
Assuming that a user enters 50, 70, and 60 as input values one after another,
separated by spaces, what is the output of the following code snippet?
int number1 = 0;
int number2 = 0;
int number3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
number1 = in.nextInt();
System.out.print("Enter a number: ");
number2 = in.nextInt();
System.out.print("Enter a number: ");
number3 = in.nextInt();
if (number1 > number2)
{
if (number1 > number3)
{
System.out.println(number1);
}
else
{
System.out.println(number3);
}
}
else
{
if (number2 > number3)
{
System.out.println(number2);
}
else
{
System.out.println(number3);
}
}
Select one:
a. 0
b. 50
c. 60
d. 70
43:
How many times does the following loop execute?
int upperCaseLetters = 0;
String str = "abcdEfghI";
boolean found = false;
for (int i = 0; i < str.length() && !found; i++)
{
char ch = str.charAt(i);
if (Character.isUpperCase(ch))
{
found = true;
}
}
Select one:
a. 9 times
b. 8 times
c. 5 times
d. 1 time
44:
What is the output of the following statements?
ArrayList
names.add("Bob");
names.add(0, "Ann");
names.remove(1);
names.add("Cal");
names.set(1, "Tony");
for (String s : names)
{
System.out.print(s + ", ");
}
Select one:
a. Cal, Bob, Ann
b. Ann, Bob
c. Ann, Tony
d. Cal, Bob, Tony
45:
An example of an output device that interfaces between computers and humans is
Select one:
a. a keyboard.
b. a mouse.
c. a speaker.
d. a microphone.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started