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 32 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
Thanks for the timely response, appreciate it


amandalm

  • Member
  • Posts: 306
Reply 3 on: Yesterday
:D TYSM

 

Did you know?

Always store hazardous household chemicals in their original containers out of reach of children. These include bleach, paint, strippers and products containing turpentine, garden chemicals, oven cleaners, fondue fuels, nail polish, and nail polish remover.

Did you know?

Chronic necrotizing aspergillosis has a slowly progressive process that, unlike invasive aspergillosis, does not spread to other organ systems or the blood vessels. It most often affects middle-aged and elderly individuals, spreading to surrounding tissue in the lungs. The disease often does not respond to conventionally successful treatments, and requires individualized therapies in order to keep it from becoming life-threatening.

Did you know?

Colchicine is a highly poisonous alkaloid originally extracted from a type of saffron plant that is used mainly to treat gout.

Did you know?

To prove that stomach ulcers were caused by bacteria and not by stress, a researcher consumed an entire laboratory beaker full of bacterial culture. After this, he did indeed develop stomach ulcers, and won the Nobel Prize for his discovery.

Did you know?

Excessive alcohol use costs the country approximately $235 billion every year.

For a complete list of videos, visit our video library