This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code.class Test { public static void main(String[] args) { StringBuilder ... (Read 28 times)

karlynnae

  • Hero Member
  • *****
  • Posts: 599

Question 1

What is displayed by the following code?

String[] tokens = "A,B;C;D".split("[,;]");
for (int i = 0; i < tokens.length; i++)
System.out.print(tokens[i] + " ");

◦ A,B;C;D
◦ A B C D
◦ A B;C;D
◦ A B C;D

Question 2

Analyze the following code.

class Test {
public static void main(String[] args) {
StringBuilder strBuf = new StringBuilder(4);
strBuf.append("ABCDE");
System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(5));
}
}

◦ The program has a compilation error because you cannot specify initial capacity in the StringBuilder constructor.
◦ The program has a runtime error because because the buffer's capacity is 4, but five characters "ABCDE" are appended into the buffer.
◦ The program compiles and runs fine.
◦ The program has a runtime error because the length of the string in the buffer is 5 after "ABCDE" is appended into the buffer. Therefore, strBuf.charAt(5) is out of range.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by karlynnae on May 6, 2020

diesoon

  • Sr. Member
  • ****
  • Posts: 353
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




karlynnae

  • Member
  • Posts: 599
Reply 2 on: May 6, 2020
:D TYSM


alvinum

  • Member
  • Posts: 317
Reply 3 on: Yesterday
Gracias!

 

Did you know?

Approximately 25% of all reported medication errors result from some kind of name confusion.

Did you know?

The average person is easily confused by the terms pharmaceutics and pharmacology, thinking they are one and the same. Whereas pharmaceutics is the science of preparing and dispensing drugs (otherwise known as the science of pharmacy), pharmacology is the study of medications.

Did you know?

Individuals are never “cured” of addictions. Instead, they learn how to manage their disease to lead healthy, balanced lives.

Did you know?

Each year in the United States, there are approximately six million pregnancies. This means that at any one time, about 4% of women in the United States are pregnant.

Did you know?

Malaria was not eliminated in the United States until 1951. The term eliminated means that no new cases arise in a country for 3 years.

For a complete list of videos, visit our video library