Java Questions: 1.What will be the value inside the variables x and y after the
ID: 3674172 • Letter: J
Question
Java Questions:
1.What will be the value inside the variables x and y after the given set of assignments?
a. x= 40, y = 20
b. x = 20, y = 10
c.x= 10, y = 20
d. x = 20, y = 20
2. Which of the following options is valid with reference to the code snippet?
Select one:
a. The value inside the variable r will be 0.326
b. The value inside the variable r will be 5.036
c. Variable r has to be defined as an integer because the % operator always returns an integer
d. The initialization of variable r is wrong, because the % operator expects integer values as operands
3.Which one of the following is an assignment statement?
Select one:
a. int a = 20;
b. a = 20;
c. assign a = 20;
d. assign 20 to a;
4.Which statement about number literals in Java is false?
Select one:
a. Numbers in exponential notation always have type double
b. Zero is an integer
c. Integers must be positive
d. An integer with fractional part of .0 has type double.
5.Assuming that the user inputs “Joe” at the prompt, what is the output of the following code snippet?
Select one:
a. The code snippet does not compile because the += operator cannot be used in this context.
b. Joe, Good morning
c. , Good morning
d. Joe
6. Suppose a phone number, stored as a ten-character string (of digits only) called phoneNumber, must be converted into a string that has parentheses around the area code. Which statement below will do that?
Select one:
a. String newNumber = "(" + phoneNumber.substring(3, 0) + ")";
b. String newNumber = "(" + ")" + phoneNumber;
c. String newNumber = "(" + phoneNumber.substring(1, 3) + ")" + phoneNumber.substring(3, 7);
d. String newNumber = "(" + phoneNumber.substring(0, 3) + ")" + phoneNumber.substring(3, 10);
7.
Which of the given statements generates the following output?
\"///
Select one:
a. System.out.println("\"///");
b. System.out.println("\\\"///");
c. System.out.println("\\\""//////");
d. System.out.println("\"///");
8. How do you compute the length of the string str?
Select one:
a. length(str)
b. length.str
c. str.length
d. str.length()
9.Which of the given System.out.print statements generates the following output?
Select one:
a. System.out.println("ABCDE"\");
b. System.out.println("ABCDE"");
c. System.out.println("ABCDE");
d. System.out.println("ABCDE"");
10.How do you extract the first 5 characters from the string str?
Select one:
a. substring(str, 5)
b. substring.str(0, 5)
c. str.substring(5)
d. str.substring(0, 5)
11.What does the following statement sequence print?
Select one:
a. Java is powerful
b. Java + is powerful
c. is powerful
d. Nothing; compile-time error
12.Which of the following options declares a float variable?
Select one:
a. Float age;
b. flt age;
c. float age;
d. age: float;
Explanation / Answer
1)
y=x/2 => 20/2 =>10
ans-b(20,10)
2)
ans-b
The value inside the variable r will be 0.326
45.326%9=0.326;
3)
ans-a
int a=20;
4)
ans-d
An integer with fractional part of .0 has type double
5)
joe+=", Good morning";
Joe, Good morning
ans-b
6)
ans-d
String newNumber = "(" + phoneNumber.substring(0, 3) + ")" + phoneNumber.substring(3, 10);
substring(starting index,ending index);
7) ans-c
System.out.println("\\\""//////");
8)
ans-d
str.length()
9)
ans-a
a. System.out.println("ABCDE"\");
10)
ans-d
str.substring(0, 5)
11)
ans-d
12) ans-c
float age
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.