SlideShare a Scribd company logo
1 of 2
Download to read offline
1. Tracing Programs
For each program below, show what is displayed on the screen when the code executes.
A. import java.util.Arrays;
public class ReferenceSemantics
{
public static int mystery(int a, int [] b)
{
a++;
b[0] = 0;
b = new int[4];
return a / 2;
}
public static void main(String [] args)
{
int x = 10;
int [] y = {3, -3, 3};
x = x + mystery(x, y);
System.out.println(x);
System.out.println(Arrays.toString(y));
}
}
B. public class NestedCalls
{
public static int mystery1(int a)
{
System.out.println("m 1");
return a / 2;
}
public static String mystery2(int b)
{
String s = "m 2";
System.out.println(s);
for(int i=0; i
Solution
1 A)
Output:
15
[0, -3, 3]
First output reason:
x = x + mystery(x, y);
In above statement x is 10 mystery will return 5 (i.e., 11/2). So result is 15.
Second output reason:
int [] y = {3, -3, 3};
System.out.println(Arrays.toString(y));
Inside the function mystery we have a statement b[0] = 0; So y[0] becomes 0 and rest values are
not changed and displayed.
1 B)
Output:
main
m 1
m 2
m 2 0 1
end main
1st output reason: main because: System.out.println("main");
2nd output reason: m 1 because: System.out.println(mystery2(mystery1(4)));
First mystery1(4) within the function we have System.out.println("m 1");
3rd output reason: m 2 0 1 because return a / 2; will return 2.
now it is mystery2(2)
inside the function we have String s = "m 2"; System.out.println(s);
after this we have
for(int i=0; i

More Related Content

Similar to 1. Tracing Programs For each program below, show what is displayed.pdf

WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
MaruMengesha
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
info30292
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Sunil Kumar Gunasekaran
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
anithareadymade
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
MaruMengesha
 

Similar to 1. Tracing Programs For each program below, show what is displayed.pdf (20)

Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
Java oops features
Java oops featuresJava oops features
Java oops features
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
 
Operators
OperatorsOperators
Operators
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
 
import java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdfimport java.util.Scanner; public class Palin { public static v.pdf
import java.util.Scanner; public class Palin { public static v.pdf
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
Oot practical
Oot practicalOot practical
Oot practical
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
public class TrequeT extends AbstractListT { .pdf
  public class TrequeT extends AbstractListT {  .pdf  public class TrequeT extends AbstractListT {  .pdf
public class TrequeT extends AbstractListT { .pdf
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
 
Trace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docxTrace the following part of codes step by step- Show exactly what it w.docx
Trace the following part of codes step by step- Show exactly what it w.docx
 

More from siennatimbok52331

please explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdfplease explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdf
siennatimbok52331
 
Please I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdfPlease I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdf
siennatimbok52331
 
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdfPlease answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
siennatimbok52331
 
Introduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdfIntroduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdf
siennatimbok52331
 
Determine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdfDetermine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdf
siennatimbok52331
 
Describe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdfDescribe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdf
siennatimbok52331
 
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdfCase 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
siennatimbok52331
 

More from siennatimbok52331 (20)

SKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdfSKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdf
 
please explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdfplease explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdf
 
Please I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdfPlease I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdf
 
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdfPlease answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
 
Consider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdfConsider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdf
 
Match the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdfMatch the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdf
 
Is the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdfIs the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdf
 
Introduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdfIntroduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdf
 
Is this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdfIs this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdf
 
Function of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdfFunction of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdf
 
Explain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdfExplain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdf
 
Discrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdfDiscrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdf
 
Discuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdfDiscuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdf
 
Determine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdfDetermine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdf
 
Describe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdfDescribe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdf
 
Describe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdfDescribe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdf
 
Company B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdfCompany B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdf
 
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdfCase 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
 
A Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdfA Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdf
 
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdfA bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

1. Tracing Programs For each program below, show what is displayed.pdf

  • 1. 1. Tracing Programs For each program below, show what is displayed on the screen when the code executes. A. import java.util.Arrays; public class ReferenceSemantics { public static int mystery(int a, int [] b) { a++; b[0] = 0; b = new int[4]; return a / 2; } public static void main(String [] args) { int x = 10; int [] y = {3, -3, 3}; x = x + mystery(x, y); System.out.println(x); System.out.println(Arrays.toString(y)); } } B. public class NestedCalls { public static int mystery1(int a) { System.out.println("m 1"); return a / 2; } public static String mystery2(int b) { String s = "m 2"; System.out.println(s); for(int i=0; i Solution
  • 2. 1 A) Output: 15 [0, -3, 3] First output reason: x = x + mystery(x, y); In above statement x is 10 mystery will return 5 (i.e., 11/2). So result is 15. Second output reason: int [] y = {3, -3, 3}; System.out.println(Arrays.toString(y)); Inside the function mystery we have a statement b[0] = 0; So y[0] becomes 0 and rest values are not changed and displayed. 1 B) Output: main m 1 m 2 m 2 0 1 end main 1st output reason: main because: System.out.println("main"); 2nd output reason: m 1 because: System.out.println(mystery2(mystery1(4))); First mystery1(4) within the function we have System.out.println("m 1"); 3rd output reason: m 2 0 1 because return a / 2; will return 2. now it is mystery2(2) inside the function we have String s = "m 2"; System.out.println(s); after this we have for(int i=0; i