Question

In: Computer Science

Fill in each blank with the correct answer/output. Assume each statement happens in order and that...

Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement. Hand trace this code instead of using your IDE. String s = "abcdefghijklmnop"; ArrayList r = new ArrayList(); r.add("abc"); r.add("cde"); r.set(1,"789"); r.add("xyz"); r.add("123"); Collections.sort(r); r.remove(2); The first index position in an array is __________. System.out.print( s.substring(0,1) ); // LINE 2 System.out.print( s.substring(2,3) ); // LINE 3 System.out.print( s.substring(5,6) ); // LINE 4 System.out.print( r.get(0) ); // LINE 5 System.out.print(r.get(0).substring(0,1)); // LINE 6 System.out.print( r.get(2) ); // LINE 7 System.out.print( r.indexOf("123")); // LINE 8 System.out.print( r.contains("abc")); // LINE 9 System.out.print( r.isEmpty()); // LINE 10 r.set(1, "\\\\"); System.out.print(r); // LINE 11 r.remove(1); System.out.print(r); // LINE 12 r.add("one"); System.out.print(r); // LINE 13 r.add(0,"five"); System.out.print(r); // LINE 14 r.clear(); System.out.print(r); // LINE 15 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.

Solutions

Expert Solution

String s = "abcdefghijklmnop";
ArrayList r = new ArrayList();
r.add("abc");
r.add("cde");
r.set(1,"789");
r.add("xyz");
r.add("123");
Collections.sort(r);
Value of the list r here is [123, 789, abc, xyz]

r.remove(2);
Value of the list r here is [123, 789, xyz]

System.out.print( s.substring(0,1) ); // LINE
This prints first character of String s
It prints a

System.out.print( s.substring(2,3) ); // LINE 3
This prints third character of String s
It prints c

System.out.print( s.substring(5,6) ); // LINE 4
This prints sixth character of String s
It prints f

System.out.print( r.get(0) ); // LINE 5
It prints first element in the list r
It prints 123

System.out.print(((String) r.get(0)).substring(0,1)); // LINE 6
It prints first character of first elment in the list
So, It prints 1

System.out.print( r.get(2) ); // LINE 7
It prints Second element in the list

System.out.print( r.indexOf("123")); // LINE 8
It prints index of "123" in list r

System.out.print( r.contains("abc")); // LINE 9
It prints true if "abc" in the list or It prints false

System.out.print( r.isEmpty()); // LINE 10
It prints true if the list is empty or It prints false

r.set(1, "\\\\"); System.out.print(r); // LINE 11
Sets the value at index to \\

r.remove(1);
removes value at index 1

System.out.print(r); // LINE 12
prints the list 

r.add("one");
appends value "one" to list

System.out.print(r);
prints the list

// LINE 13
r.add(0,"five");
adds "five" at start

System.out.print(r); // LINE 14
prints the list

r.clear();
clears the list 

System.out.print(r); // LINE 15
prints the list



The first index position in an array is 0

Output:
--------
a
c
f
123
1
xyz
0
false
false
[123, \\, xyz]
[123, xyz]
[123, xyz, one][five, 123, xyz, one]
[]



Related Solutions

Fill in the blank with the correct answer by typing in the box. The GDP deflator...
Fill in the blank with the correct answer by typing in the box. The GDP deflator is a price index that _______________ all the components of GDP (that is, consumption plus investment plus government plus exports minus imports).
Answer the following questions (choose the correct answer or fill in the blank): If 3500 kcals...
Answer the following questions (choose the correct answer or fill in the blank): If 3500 kcals eaten in excess equals one pound of weight gain, what would be the approximate weight gain of a person who consumes an excess of 500 kcals every day for 2 weeks? 1 lb. 2 lbs. 3 lbs. 4 lbs. The __________________________ is a brain center that controls activities such as maintenance of water balance, regulation of body temperature, and control of appetite. What percentage...
Fill in the blank with the correct answer. Amounts owed to suppliers for goods and services...
Fill in the blank with the correct answer. Amounts owed to suppliers for goods and services that have been provided to the entity on credit are called ______________________________________. A current liability that represents cash collected in advance of earning the related revenue is called ____________________________________________. The portion of long-term debt that is to be paid within one year of the balance sheet date is reclassified from the non-current liability section of the balance sheet and called ______________________________________________________. Total wages earned...
Fill in the blank with the answer. Each answer in the list may be used more...
Fill in the blank with the answer. Each answer in the list may be used more than once or not at all. a.Separate and proportionate b.Racketeer Influenced and Corrupt Organization Act (RICO) c.Foreign Corrupt Practices Act d.Fraud e.Negligence f.Reasonable professional care g.Gross negligence h.Securities Act of 1933 i.Compensatory damages j.Damages k.Criminal victim compensation l.Punitive damages m.Hochfelder n.Ultramares o.Privity p.Near privity q.Standing r.Deposition s.Constructive fraud t.Breach of contract u.Joint and severally v.Securities Exchange Act of 1934 _____1.A federal statute used for...
Fill the blank with the correct word from the word blank Because of the adverse selection...
Fill the blank with the correct word from the word blank Because of the adverse selection problem in the financial market, a firm’s newly issued stocks or bonds could be ( ) so that the firm would withdraw from the market. It will leave only the ( ) credit firms in the market. To solve the asymmetric information problem between the lenders and borrowers, ( ) could be used as a good mechanism for ensuring that a borrower is likely...
Fill the blank with the correct word from the word blank Because of the adverse selection...
Fill the blank with the correct word from the word blank Because of the adverse selection problem in the financial market, a firm’s newly issued stocks or bonds could be ( ) so that the firm would withdraw from the market. It will leave only the ( ) credit firms in the market. To solve the asymmetric information problem between the lenders and borrowers, ( ) could be used as a good mechanism for ensuring that a borrower is likely...
FILL IN THE BLANK: (The size of the blank has nothing to do with the answer)...
FILL IN THE BLANK: (The size of the blank has nothing to do with the answer) 1. The _____ propensity to consume is the change in _____ from a one unit increase in aggregate income or output 2. When a country has a stabilization________ it will use Keynesian fiscal stimulus whenever real GDP was expected to fall short of the full ___________ output level. 3. The _________ out effect occurs when government borrowing leads to higher _________ rates and lower...
FILL IN THE CORRECT TERMINOLOGIES IN THE BLANK SPACES _____ 1. a. Any cost that the...
FILL IN THE CORRECT TERMINOLOGIES IN THE BLANK SPACES _____ 1. a. Any cost that the management of a responsibility center cannot affect within a given time span. _____ 2. b.Units that exist only to support other departments or customers. _____ 3. c. Characteristics or attributes that managers must achieve in order to drive the organization toward its goals. _____ 4. d. A measure of income divided by the investment required to obtain that income. _____ 5. e. The effort...
PLEASE FILL IN BLANK WITH CORRECT ANSWER. THANK YOU! CHAPTER 16: ANALYSIS OF VARIANCE (ONE WAY-Factor)...
PLEASE FILL IN BLANK WITH CORRECT ANSWER. THANK YOU! CHAPTER 16: ANALYSIS OF VARIANCE (ONE WAY-Factor) Key Terms Analysis of variance (ANOVA) – An overall test of the null hypothesis fro more than two population means. One-way ANOVA – The simplest type of analysis of variance that tests whether differences exist among population means categorized by only one factor or independent variable. Treatment effect – The existence of at least one difference between the population means categorized by the independent...
I. Fill in the blank by matching the high level construct correct number to the corresponding...
I. Fill in the blank by matching the high level construct correct number to the corresponding letter of the instruction sequence. Write one sentence to support your answer. 1. Access the disk block i.    2. Enqueue x into Q.     3. C= AX B where A, B, C are matrices.   4. Send file f to printer P.      5. Load program p into memory and execute p. Copy f into a temporary file f'. Wait until printer P not busy. Reserve printer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT