SlideShare uma empresa Scribd logo
1 de 2
Explain this code, please.
Code
public class Question8
{
public static void main(String[] args)
{
int[] nums = {2, 4, 6, 8};
for (int i = 0; i < nums.length; ++i)
System.out.println("nums[" + i + "] = " + nums[i]);
System.out.println();
fun(nums);
for (int i = 0; i < nums.length; ++i)
System.out.println("nums[" + i + "] = " + nums[i]);
}
public static void fun(int[] arr)
{
for (int i = 0; i < arr.length; i+=2)
arr[i] -= 1;
}
}
Run
nums[0] = 2
nums[1] = 4
nums[2] = 6
nums[3] = 8
nums[0] = 1
nums[1] = 4
nums[2] = 5
nums[3] = 8
Solution
In the first loop i start at value 0 and in each iteration we are printing ("nums[" + i + "] = " +
nums[i]). So for i = 0 this becomes nums[0] = 2. Next the value of i becomes 1 and then 2 and
then 3 and the loop breaks.
Now we call the function fun in which there is a loop. The value of i initially is 0 and we are
subtracting one from it. So the value of nums[0] becomes 1 and now the value of i becomes 2
and nums[2] becomes 5 and then the value of i becomes 4 and the loop exits. That explain the
first set of output.
nums[0] = 2
nums[1] = 4
nums[2] = 6
nums[3] = 8
So now with the loop the values of nums will be 1,4,5,8. Because the values are changed in the
function. That explain the second set of output.
nums[0] = 1
nums[1] = 4
nums[2] = 5
nums[3] = 8

Mais conteúdo relacionado

Semelhante a Explain this code- please- Code public class Question8 { public stati.docx

ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptMahyuddin8
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA ProgramTrenton Asbury
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdfAnkitchhabra28
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
 
ch07-arrays.ppt
ch07-arrays.pptch07-arrays.ppt
ch07-arrays.pptMahyuddin8
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdfICADCMLTPC
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: ArraysMartin Chapman
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
Java_Programming_by_Example_6th_Edition.pdf
Java_Programming_by_Example_6th_Edition.pdfJava_Programming_by_Example_6th_Edition.pdf
Java_Programming_by_Example_6th_Edition.pdfJayveeCultivo
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...MaruMengesha
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.pptFareedIhsas
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtractionCharm Sasi
 

Semelhante a Explain this code- please- Code public class Question8 { public stati.docx (20)

ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Studyx4
Studyx4Studyx4
Studyx4
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 
ch07-arrays.ppt
ch07-arrays.pptch07-arrays.ppt
ch07-arrays.ppt
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: Arrays
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
Java_Programming_by_Example_6th_Edition.pdf
Java_Programming_by_Example_6th_Edition.pdfJava_Programming_by_Example_6th_Edition.pdf
Java_Programming_by_Example_6th_Edition.pdf
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Parameters
ParametersParameters
Parameters
 
EXPT1.pptx
EXPT1.pptxEXPT1.pptx
EXPT1.pptx
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtraction
 

Mais de james876543264

Astronomy 107- 1- Why does helium fusion require a higher temperature.docx
Astronomy 107- 1- Why does helium fusion require a higher temperature.docxAstronomy 107- 1- Why does helium fusion require a higher temperature.docx
Astronomy 107- 1- Why does helium fusion require a higher temperature.docxjames876543264
 
Astronomers have found dark matter in a variety of environments- Name.docx
Astronomers have found dark matter in a variety of environments- Name.docxAstronomers have found dark matter in a variety of environments- Name.docx
Astronomers have found dark matter in a variety of environments- Name.docxjames876543264
 
Assume that LO and HI have already been assigned as constants with LO.docx
Assume that LO and HI have already been assigned as constants with LO.docxAssume that LO and HI have already been assigned as constants with LO.docx
Assume that LO and HI have already been assigned as constants with LO.docxjames876543264
 
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docx
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docxAS1- Four Condition of Deadloc- show that the four conditions of deadl.docx
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docxjames876543264
 
As we know- total ownership is not a requirement for consolidation- A.docx
As we know- total ownership is not a requirement for consolidation- A.docxAs we know- total ownership is not a requirement for consolidation- A.docx
As we know- total ownership is not a requirement for consolidation- A.docxjames876543264
 
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docx
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docxAsset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docx
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docxjames876543264
 
Ashley Wesley is the assistant controller at the Walitin Construction.docx
Ashley Wesley is the assistant controller at the Walitin Construction.docxAshley Wesley is the assistant controller at the Walitin Construction.docx
Ashley Wesley is the assistant controller at the Walitin Construction.docxjames876543264
 
Assembly language --- Area of a Polygon program Write a program to fin.docx
Assembly language --- Area of a Polygon program Write a program to fin.docxAssembly language --- Area of a Polygon program Write a program to fin.docx
Assembly language --- Area of a Polygon program Write a program to fin.docxjames876543264
 
As a transportation planner-engineer- would you implement a bus servic.docx
As a transportation planner-engineer- would you implement a bus servic.docxAs a transportation planner-engineer- would you implement a bus servic.docx
As a transportation planner-engineer- would you implement a bus servic.docxjames876543264
 
explain why glass electrode is a good example of an ion selective elec.docx
explain why glass electrode is a good example of an ion selective elec.docxexplain why glass electrode is a good example of an ion selective elec.docx
explain why glass electrode is a good example of an ion selective elec.docxjames876543264
 
explain why galvanize steel does not rust Chlorine is added to swimmin.docx
explain why galvanize steel does not rust Chlorine is added to swimmin.docxexplain why galvanize steel does not rust Chlorine is added to swimmin.docx
explain why galvanize steel does not rust Chlorine is added to swimmin.docxjames876543264
 
Explain why in the DPCM structure- the input to the predictor P is the.docx
Explain why in the DPCM structure- the input to the predictor P is the.docxExplain why in the DPCM structure- the input to the predictor P is the.docx
Explain why in the DPCM structure- the input to the predictor P is the.docxjames876543264
 
explain Westminster system- explain Westminster system- explain We.docx
explain Westminster system-    explain Westminster system-  explain We.docxexplain Westminster system-    explain Westminster system-  explain We.docx
explain Westminster system- explain Westminster system- explain We.docxjames876543264
 
Explain what anSolutionAn intervention is a deliberate process by whic.docx
Explain what anSolutionAn intervention is a deliberate process by whic.docxExplain what anSolutionAn intervention is a deliberate process by whic.docx
Explain what anSolutionAn intervention is a deliberate process by whic.docxjames876543264
 
Explain what is meant by the statement that a preferred stock is a hyb.docx
Explain what is meant by the statement that a preferred stock is a hyb.docxExplain what is meant by the statement that a preferred stock is a hyb.docx
Explain what is meant by the statement that a preferred stock is a hyb.docxjames876543264
 
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docx
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docxExplain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docx
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docxjames876543264
 
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docx
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docxExplain two Principle of locality used in Memory Hierarchy-SolutionHie.docx
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docxjames876543264
 
Explain the use of directives in configuration files- Provide an examp.docx
Explain the use of directives in configuration files- Provide an examp.docxExplain the use of directives in configuration files- Provide an examp.docx
Explain the use of directives in configuration files- Provide an examp.docxjames876543264
 
Explain the steps needed to configure RIPng and explain the advantages.docx
Explain the steps needed to configure RIPng and explain the advantages.docxExplain the steps needed to configure RIPng and explain the advantages.docx
Explain the steps needed to configure RIPng and explain the advantages.docxjames876543264
 
Explain the motivation behind using a header file for a C program-Solu.docx
Explain the motivation behind using a header file for a C program-Solu.docxExplain the motivation behind using a header file for a C program-Solu.docx
Explain the motivation behind using a header file for a C program-Solu.docxjames876543264
 

Mais de james876543264 (20)

Astronomy 107- 1- Why does helium fusion require a higher temperature.docx
Astronomy 107- 1- Why does helium fusion require a higher temperature.docxAstronomy 107- 1- Why does helium fusion require a higher temperature.docx
Astronomy 107- 1- Why does helium fusion require a higher temperature.docx
 
Astronomers have found dark matter in a variety of environments- Name.docx
Astronomers have found dark matter in a variety of environments- Name.docxAstronomers have found dark matter in a variety of environments- Name.docx
Astronomers have found dark matter in a variety of environments- Name.docx
 
Assume that LO and HI have already been assigned as constants with LO.docx
Assume that LO and HI have already been assigned as constants with LO.docxAssume that LO and HI have already been assigned as constants with LO.docx
Assume that LO and HI have already been assigned as constants with LO.docx
 
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docx
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docxAS1- Four Condition of Deadloc- show that the four conditions of deadl.docx
AS1- Four Condition of Deadloc- show that the four conditions of deadl.docx
 
As we know- total ownership is not a requirement for consolidation- A.docx
As we know- total ownership is not a requirement for consolidation- A.docxAs we know- total ownership is not a requirement for consolidation- A.docx
As we know- total ownership is not a requirement for consolidation- A.docx
 
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docx
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docxAsset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docx
Asset Depreciation 2 2 unread replies- 2 2 replies- Answer each of the.docx
 
Ashley Wesley is the assistant controller at the Walitin Construction.docx
Ashley Wesley is the assistant controller at the Walitin Construction.docxAshley Wesley is the assistant controller at the Walitin Construction.docx
Ashley Wesley is the assistant controller at the Walitin Construction.docx
 
Assembly language --- Area of a Polygon program Write a program to fin.docx
Assembly language --- Area of a Polygon program Write a program to fin.docxAssembly language --- Area of a Polygon program Write a program to fin.docx
Assembly language --- Area of a Polygon program Write a program to fin.docx
 
As a transportation planner-engineer- would you implement a bus servic.docx
As a transportation planner-engineer- would you implement a bus servic.docxAs a transportation planner-engineer- would you implement a bus servic.docx
As a transportation planner-engineer- would you implement a bus servic.docx
 
explain why glass electrode is a good example of an ion selective elec.docx
explain why glass electrode is a good example of an ion selective elec.docxexplain why glass electrode is a good example of an ion selective elec.docx
explain why glass electrode is a good example of an ion selective elec.docx
 
explain why galvanize steel does not rust Chlorine is added to swimmin.docx
explain why galvanize steel does not rust Chlorine is added to swimmin.docxexplain why galvanize steel does not rust Chlorine is added to swimmin.docx
explain why galvanize steel does not rust Chlorine is added to swimmin.docx
 
Explain why in the DPCM structure- the input to the predictor P is the.docx
Explain why in the DPCM structure- the input to the predictor P is the.docxExplain why in the DPCM structure- the input to the predictor P is the.docx
Explain why in the DPCM structure- the input to the predictor P is the.docx
 
explain Westminster system- explain Westminster system- explain We.docx
explain Westminster system-    explain Westminster system-  explain We.docxexplain Westminster system-    explain Westminster system-  explain We.docx
explain Westminster system- explain Westminster system- explain We.docx
 
Explain what anSolutionAn intervention is a deliberate process by whic.docx
Explain what anSolutionAn intervention is a deliberate process by whic.docxExplain what anSolutionAn intervention is a deliberate process by whic.docx
Explain what anSolutionAn intervention is a deliberate process by whic.docx
 
Explain what is meant by the statement that a preferred stock is a hyb.docx
Explain what is meant by the statement that a preferred stock is a hyb.docxExplain what is meant by the statement that a preferred stock is a hyb.docx
Explain what is meant by the statement that a preferred stock is a hyb.docx
 
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docx
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docxExplain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docx
Explain the weaknesses of the OOA-OOD focusing only on Use-cases and C.docx
 
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docx
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docxExplain two Principle of locality used in Memory Hierarchy-SolutionHie.docx
Explain two Principle of locality used in Memory Hierarchy-SolutionHie.docx
 
Explain the use of directives in configuration files- Provide an examp.docx
Explain the use of directives in configuration files- Provide an examp.docxExplain the use of directives in configuration files- Provide an examp.docx
Explain the use of directives in configuration files- Provide an examp.docx
 
Explain the steps needed to configure RIPng and explain the advantages.docx
Explain the steps needed to configure RIPng and explain the advantages.docxExplain the steps needed to configure RIPng and explain the advantages.docx
Explain the steps needed to configure RIPng and explain the advantages.docx
 
Explain the motivation behind using a header file for a C program-Solu.docx
Explain the motivation behind using a header file for a C program-Solu.docxExplain the motivation behind using a header file for a C program-Solu.docx
Explain the motivation behind using a header file for a C program-Solu.docx
 

Último

Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 

Último (20)

Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 

Explain this code- please- Code public class Question8 { public stati.docx

  • 1. Explain this code, please. Code public class Question8 { public static void main(String[] args) { int[] nums = {2, 4, 6, 8}; for (int i = 0; i < nums.length; ++i) System.out.println("nums[" + i + "] = " + nums[i]); System.out.println(); fun(nums); for (int i = 0; i < nums.length; ++i) System.out.println("nums[" + i + "] = " + nums[i]); } public static void fun(int[] arr) { for (int i = 0; i < arr.length; i+=2) arr[i] -= 1; } } Run nums[0] = 2 nums[1] = 4 nums[2] = 6 nums[3] = 8 nums[0] = 1 nums[1] = 4 nums[2] = 5 nums[3] = 8 Solution
  • 2. In the first loop i start at value 0 and in each iteration we are printing ("nums[" + i + "] = " + nums[i]). So for i = 0 this becomes nums[0] = 2. Next the value of i becomes 1 and then 2 and then 3 and the loop breaks. Now we call the function fun in which there is a loop. The value of i initially is 0 and we are subtracting one from it. So the value of nums[0] becomes 1 and now the value of i becomes 2 and nums[2] becomes 5 and then the value of i becomes 4 and the loop exits. That explain the first set of output. nums[0] = 2 nums[1] = 4 nums[2] = 6 nums[3] = 8 So now with the loop the values of nums will be 1,4,5,8. Because the values are changed in the function. That explain the second set of output. nums[0] = 1 nums[1] = 4 nums[2] = 5 nums[3] = 8