Question: Java Questions: 1.What will be the value inside the variables x and y after the given set of assignments? int x = 20; int y

Java Questions:

1.What will be the value inside the variables x and y after the given set of assignments?

int x = 20; 
int y = 10; 
x = (x - y) * 2; 
y = x / 2; 

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?

public static void main(String[] args) 
{ 
 double d = 45.326; 
 double r = d % 9.0; 
 System.out.println(r); 
} 

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?

public static void main(String[] args) 
{ 
 System.out.print("Enter your name "); 
 String name; 
 Scanner in = new Scanner(System.in); 
 name = in.next(); 
 name += ", Good morning"; 
 System.out.print(name); 
} 

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?

ABCDE"\ 

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?

final String str = "Java"; 
str += " is powerful"; 
System.out.println(str); 

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;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!