Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi All,could you please help me with these also. 1-Which one of the following st

ID: 3664956 • Letter: H

Question

Hi All,could you please help me with these also.

1-Which one of the following statements can be used to extract the last 10 characters from the string variable str? a. str.substring(str.length() - 10, str.length()) b. str.substring(10, str.length()) c. str.substring(str.length() - 9, 10) d. str.substring(0, 10).

2-

Which one of the following statements displays the output as +00321.00?

System.out.printf("+%09.2f", 321.0);

System.out.printf("%009,2f", 321.0);

System.out.printf("+9.2f", 321.0);

System.out.printf("%09.00f", 321.0);

___________________ 3-

The new pay is 25000

The new pay is 25100

The new pay is 27500

The new pay is 30000

___________________________

4-

What is wrong with the following code snippet?

int average;
average = 78A;

The average variable is never initialized.

The data type for the average variable is not specified.

The average variable is never assigned a value.

The average variable is assigned a non-numeric value.

___________________

5_

What is the correct way to invoke methods on variables in Java that are strings?

Methods can only be invoked on string constants, not on variables.

For each method there is a special operator that must be used.

There are no methods available in Java for string variables.

d.

Invoke them using the variable name and the dot (.) notation.

________________________________

7-

0

4

20

There will be no output due to a run-time error.

8-

Which one of the following statements can be used to extract the last five characters from any string variable str?

str.substring(str.length() - 5, str.length())

str.substring(5, 5)

str.substring(str.length() - 4, 5)

str.substring(str.length() - 5, 5)

_____________________

a.

System.out.printf("+%09.2f", 321.0);

b.

System.out.printf("%009,2f", 321.0);

c.

System.out.printf("+9.2f", 321.0);

d.

System.out.printf("%09.00f", 321.0);

___________________ 3-

Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus rate in the following code snippet, what is the output?

a.

The new pay is 25000

b.

The new pay is 25100

c.

The new pay is 27500

d.

The new pay is 30000

Explanation / Answer

Below are the given right option for the following question:

1-Which one of the following statements can be used to extract the last 10 characters from the string variable str? a. str.substring(str.length() - 10, str.length()) b. str.substring(10, str.length()) c. str.substring(str.length() - 9, 10) d. str.substring(0, 10).

a. str.substring(str.length() - 10, str.length()) because this is the proper function to extract string variable .

2) Which one of the following statements displays the output as +00321.00?

a) System.out.printf("+%09.2f", 321.0);
b) System.out.printf("%009,2f", 321.0);
c) System.out.printf("+9.2f", 321.0);
d) System.out.printf("%09.00f", 321.0);

a) System.out.printf("+%09.2f", 321.0); DEFINE THE FORMAT the output as +00321.00

3. Assuming that the user inputs a value of 25000 for the pay and 10 for the bonus rate in the following code snippet, what is the output?

public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the pay: ");
double pay = in.nextDouble();
System.out.print("Enter the bonus rate: ");
double bonus = in.nextDouble();

System.out.println("The new pay is " +
(pay + pay * (bonus / 100.0)));
}

a) The new pay is 25000
b) The new pay is 25100
c) The new pay is 27500
d) The new pay is 30000

c) The new pay is 27500 BECAUSE WHEN WE COMPILE THE CODE AND RUN WITH THE GIVEN VALUE THE FOLLOWING OUTPUT WE GET.

4. What is wrong with the following code snippet?

int average;
average = 78A;

a) The average variable is never initialized.
b) The data type for the average variable is not specified.
c) The average variable is never assigned a value.
d) The average variable is assigned a non-numeric value.

d) The average variable is assigned a non-numeric value.

5 What is the correct way to invoke methods on variables in Java that are strings?

a) Methods can only be invoked on string constants, not on variables.
b) For each method there is a special operator that must be used.
c) There are no methods available in Java for string variables.
d) Invoke them using the variable name and the dot (.) notation.

d) Invoke them using the variable name and the dot (.) notation.

7) What is the output of the following code snippet?
public static void main(String[] args)
{
int var1 = 10;
int var2 = 2;
int var3 = 20;
var3 = var3 / (var1 % var2);
System.out.println(var3);
}
a) 0
b) 4
c) 20
d) There will be no output due to a run-time error.

d) There will be no output due to a run-time error. BECAUSE OF THIS

var3 = var3 / (var1 % var2);

System.out.println(var3);

8- Which one of the following statements can be used to extract the last five characters from any string variable str?

a.

str.substring(str.length() - 5, str.length())

b.

str.substring(5, 5)

c.

str.substring(str.length() - 4, 5)

d.

str.substring(str.length() - 5, 5)

a.

str.substring(str.length() - 5, str.length())

BECAUSE THIS IS THE VALID FUCTION TO EXTRACT THE VALUE

a.

str.substring(str.length() - 5, str.length())

b.

str.substring(5, 5)

c.

str.substring(str.length() - 4, 5)

d.

str.substring(str.length() - 5, 5)