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 47 times)

Anajune7

  • Hero Member
  • *****
  • Posts: 574

Question 1

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

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

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

Question 2

Analyze the following code:

public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4};
int[] y = x;
x = new int[2];
for (int i = 0; i < y.length; i++)
System.out.print(y[i] + " ");
}
}

◦ The program displays 1 2 3 4
◦ The program displays 0 0 3 4
◦ The program displays 0 0 0 0
◦ The program displays 0 0


Related Topics

Need homework help now?

Ask unlimited questions for free

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

Alyson.hiatt@yahoo.com

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




Anajune7

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


miss.ashley

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

 

Did you know?

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

Did you know?

Hyperthyroidism leads to an increased rate of metabolism and affects about 1% of women but only 0.1% of men. For most people, this increased metabolic rate causes the thyroid gland to become enlarged (known as a goiter).

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?

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

Did you know?

The Centers for Disease Control and Prevention (CDC) was originally known as the Communicable Disease Center, which was formed to fight malaria. It was originally headquartered in Atlanta, Georgia, since the Southern states faced the worst threat from malaria.

For a complete list of videos, visit our video library