Question 11 What does the following statement sequence print? String str = \"Jav
ID: 3667935 • Letter: Q
Question
Question 11
What does the following statement sequence print?
String str = "Java Is Good";
int n = str.length();
String mystery = str.substring(n - 4, n) +
str.charAt(4) + str.substring(0, 4);
System.out.println(mystery);
Question 12
What does the following statement sequence print?
String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 2, n);
System.out.println(mystery);
Question 13
0 out of 0.5 points
Assuming that the user enters 23 and 45 as inputs for num1 and num2, respectively, what is the output of the following code snippet?
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
String num1 = in.next();
System.out.print("Enter another number: ");
String num2 = in.next();
System.out.println(num1 + num2);
}
Question 14
Which of the following statements is correct about constants?
:
.
Question 15
Which is the appropriate time to initialize a variable?
What does the following statement sequence print?
String str = "Java Is Good";
int n = str.length();
String mystery = str.substring(n - 4, n) +
str.charAt(4) + str.substring(0, 4);
System.out.println(mystery);
Explanation / Answer
Answer 11: Good Java
Exp: Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
Output of str.substring(n - 4, n) : Good
Output of str.charAt(4) + str.substring(0, 4) : java
Answer 12: Hry
Exp: The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Output of str.substring(0, 1) = H
Output of str.substring(n - 2, n) = ry
Answer 13: 2345
explanation: the + operator is used to concat two strings in java.
Answer 15: We should initilize variable before we use it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.