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 33 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
YES! Correct, THANKS for helping me on my review


anyusername12131

  • Member
  • Posts: 327
Reply 3 on: Yesterday
Thanks for the timely response, appreciate it

 

Did you know?

A strange skin disease referred to as Morgellons has occurred in the southern United States and in California. Symptoms include slowly healing sores, joint pain, persistent fatigue, and a sensation of things crawling through the skin. Another symptom is strange-looking, threadlike extrusions coming out of the skin.

Did you know?

HIV testing reach is still limited. An estimated 40% of people with HIV (more than 14 million) remain undiagnosed and do not know their infection status.

Did you know?

A seasonal flu vaccine is the best way to reduce the chances you will get seasonal influenza and spread it to others.

Did you know?

In most cases, kidneys can recover from almost complete loss of function, such as in acute kidney (renal) failure.

Did you know?

Cucumber slices relieve headaches by tightening blood vessels, reducing blood flow to the area, and relieving pressure.

For a complete list of videos, visit our video library