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

Author Question: Analyze the following code:public class Test { public static void main(String[] args) { int[] x = ... (Read 59 times)

bobbysung

  • Hero Member
  • *****
  • Posts: 519

Question 1

In the following code, what is the printout for list2?

class Test {
public static void main(String[] args) {
int[] list1 = {3, 2, 1};
int[] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = list2.length - 1; i >= 0; i--)
System.out.print(list2[i] + " ");
}
}

◦ 0 1 3
◦ 2 1 0
◦ 1 2 3
◦ 3 2 1
◦ 0 1 2

Question 2

Analyze the following code:

public class Test {
public static void main(String[] args) {
int[] x = {0, 1, 2, 3, 4, 5};
xMethod(x, 5);
}

public static void xMethod(int[] x, int length) {
for (int i = 0; i < length; i++)
System.out.print(" " + x[i]);
}
}

◦ The program displays 0 1 2 3 4 and then raises a runtime exception.
◦ The program displays 0 1 2 3 4.
◦ The program displays 0 1 2 3 4 5 and then raises a runtime exception.
◦ The program displays 0 1 2 3 4 5.


Related Topics

Need homework help now?

Ask unlimited questions for free

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

jazzlynnnnn

  • Sr. Member
  • ****
  • Posts: 335
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




bobbysung

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


fatboyy09

  • Member
  • Posts: 358
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

The strongest synthetic topical retinoid drug available, tazarotene, is used to treat sun-damaged skin, acne, and psoriasis.

Did you know?

The most destructive flu epidemic of all times in recorded history occurred in 1918, with approximately 20 million deaths worldwide.

Did you know?

The U.S. Preventive Services Task Force recommends that all women age 65 years of age or older should be screened with bone densitometry.

Did you know?

The average older adult in the United States takes five prescription drugs per day. Half of these drugs contain a sedative. Alcohol should therefore be avoided by most senior citizens because of the dangerous interactions between alcohol and sedatives.

Did you know?

Of the estimated 2 million heroin users in the United States, 600,000–800,000 are considered hardcore addicts. Heroin addiction is considered to be one of the hardest addictions to recover from.

For a complete list of videos, visit our video library