comp sci

What is the output of the following statement:
int n = 2
10
1;
System.out.println("n is" + n);
A "n is" + n
B n is 20
C n is 20
D n is20
E none of these are the output

D n is20

The expression 4 + 20 / (3 - 1) * 2 is evaluated to ________.
A 20
B 25
C 4
D 9
E 24

E 24

According to Java naming convention, which of the following names can be variables?
A TOTAL_LENGTH
B class
C totalLength
D findArea
E FindArea

C totalLength
D findArea

) Which of the following is a constant, according to Java naming conventions?
A Test
B ReadInt
C MAX_VALUE
D read
E COUNT

C MAX_VALUE
E COUNT

________ is a program that runs on a computer to manage and control a computer's activities.
A Modem
B Operating System
C Compiler
D Java
E Interpreter

B Operating System

public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
What is the output of the last println?
A But not in Texas
B But not

C But notin Texas

public class Questions
{
public static void main(String[ ] args)
{
System.out.print("Here");
System.out.println("There " + "Everywhere");
System.out.println("But not" + "in Texas");
}
}
How many lines of output will there be?
A 1
B 2
C 3
D 4
E 5

B 2

Consider the following statement:
System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
This statement will output ___ lines of text
A 1
B 2
C 3
D 4
E 5

B 2

Consider the following statement:
System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
What is the output?
A 1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night
B 1 big bad wolf 8 the 3 little pigs
4 dinner 2night
C 1 big bad wol

B 1 big bad wolf 8 the 3 little pigs
4 dinner 2night

If x is an int and y is a double, all of the following are legal except which
assignment statement?
A y = x;
B x = y;
C y = (double) x;
D x = (int) y;
E All are legal

B x = y;

What will be the result of the following assignment statement? Assume b = 5 and
c = 10.
int a = b * (-c + 2) / 2;
A 30
B -30
C 20
D -20
E -6

D -20

What value will z have if we execute the following assignment statement?
double z = 5 / 10;
A z will equal 0.0
B z will equal 0.5
C z will equal 5.0
D z will equal 0.05
E a run-time error arises because z is a double and 5 / 10 is an int

A z will equal 0.0

What value will z have if we execute the following assignment statement?
int z = 50 / 10.00;
A 5
B 5.0
C 50
D 10
E a run-time error arises because z is an int and 50 / 10.00 is not

E a run-time error arises because z is an int and 50 / 10.00 is not

If x is an int and y is a double, all of the following are legal except which
assignment statement?
1) y= x
2) x = y
3) y = (double) x
4) x = (double) y
5) all of the above are legal
A y = x;
B x = y;
C y = (double) x;
D x = (int) y;
E all are legal

B x = y;

Given the following assignment statement, which of the following answers is true
regarding the order that the operators will be applied based on operator
precedence?
a = (b + c) * d / e - f;
A *, /, +, -
B *, +, /, -
C +, *, /, -
D +, /, *, -
E +, -, *, /

C +, *, /, -

What will be the result of the following assignment statement? Assume b = 5 and
c = 10.
int a = b * (-c + 2) / 2;
A 30
B -30
C 20
D -20
E -6

D -20

What is output with the statement System.out.println(x+y); if x and y are int
values where x=10 and y=5?
A 15
B 105
C 10 5
D x+y
E An error since neither x nor y is a String

A 15

What is output with the statement System.out.println(""+x+y); if x and y are int
values where x=10 and y=5?
A 15
B 105
C 10 5
D x+y
E An error since neither x nor y is a String

b. Explanation: The "" casts the rest of the expression as a String, and so the two + signs are used as
String concatenation, and so x + y becomes x concatenated with y, or 105.

If you want to store into the String name the value "George Bush", you would use
which statement?
A String name = "George Bush";
B String name = new String("George Bush");
C String name = "George" + " " + "Bush";
D String name = new String("George" + "

E Any of the above would work

In the String major = "Computer Science", what is returned by major.charAt(1)?
A 'C'
B 'o'
C 'm'
D "C"
E "Computer

B "o' Explanation: Neither d nor e would be correct because charAt returns a char (single character)
whereas these answers are Strings. So, the question is, which character is returned? In Java, the first character of a
String is numbered 0. So charAt(1)

Which of the following would return the last character of the String x?
A x.charAt(0);
B x.charAt(last);
C x.charAt(length(x));
D x.charAt(x.length( )-1);
E x.charAt(x.length( ));

D x.charAt(x.length( )-1);

Which library package would you import to use the class Random?
A java.beans
B java.io
C java.lang
D java.text
E java.util

E java.util

6. Since you cannot take the square root of a negative number, you might use
which of the following instructions to find the square root of the variable x?
a)Math.sqrt(x*x);
b)Math.sqrt((int) x);
c)Math.sqrt(Math.abs(x));
d)Math.abs(Math.sqrt(x));
e)Math.

C Math.sqrt(Math.abs(x));