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 26 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
Great answer, keep it coming :)


Chelseyj.hasty

  • Member
  • Posts: 319
Reply 3 on: Yesterday
YES! Correct, THANKS for helping me on my review

 

Did you know?

A good example of polar molecules can be understood when trying to make a cake. If water and oil are required, they will not mix together. If you put them into a measuring cup, the oil will rise to the top while the water remains on the bottom.

Did you know?

Asthma-like symptoms were first recorded about 3,500 years ago in Egypt. The first manuscript specifically written about asthma was in the year 1190, describing a condition characterized by sudden breathlessness. The treatments listed in this manuscript include chicken soup, herbs, and sexual abstinence.

Did you know?

In 1844, Charles Goodyear obtained the first patent for a rubber condom.

Did you know?

Drying your hands with a paper towel will reduce the bacterial count on your hands by 45–60%.

Did you know?

Giardia is one of the most common intestinal parasites worldwide, and infects up to 20% of the world population, mostly in poorer countries with inadequate sanitation. Infections are most common in children, though chronic Giardia is more common in adults.

For a complete list of videos, visit our video library