SlideShare a Scribd company logo
1 of 2
Download to read offline
What will be the output from the following code if the user enters 4.
int[] list = {1, 4, 4, 2, 5, -3, 6, 2};
int toSearch = input.nextInt();
int location = -1;
for(int i = 0; i < list.length; i++) {
if(list[i] == toSearch) {
location = i;
}
}
System.out.print(location);
Solution
Program:
import java.io.*;
import java.util.Scanner;
public class Ary
{
public static void main(String[] args)
{
int[] list = {1, 4, 4, 2, 5, -3, 6, 2};
Scanner input = new Scanner(System.in); // here we are scanning the input from the user
int toSearch = input.nextInt();
int location = -1;
for(int i = 0; i < list.length; i++) {
if(list[i] == toSearch) {
location = i;
}
}
System.out.println(location); // here we are printing the corresponding element in the list based
on user input
}
}
//if the user enters number 4 the output of the above code is as follows
Output:
4
2

More Related Content

Similar to What will be the output from the following code if the user enters 4.pdf

Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIjagriti srivastava
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
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
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docxdorisc7
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerAiman Hud
 
when I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxwhen I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxlashandaotley
 
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
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...Hiraniahmad
 
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
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjaliSoorej
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
Operators
OperatorsOperators
Operatorsvvpadhu
 
I am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfI am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfacecomputertcr
 

Similar to What will be the output from the following code if the user enters 4.pdf (20)

Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.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-...
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
when I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docxwhen I compile to get the survey title the overload constructor asks.docx
when I compile to get the survey title the overload constructor asks.docx
 
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
 
Code
CodeCode
Code
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
 
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,...
 
Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Java programs
Java programsJava programs
Java programs
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
LAB1.docx
LAB1.docxLAB1.docx
LAB1.docx
 
Operators
OperatorsOperators
Operators
 
I am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdfI am asked to provide the testing cases for the following co.pdf
I am asked to provide the testing cases for the following co.pdf
 

More from anavmuthu

What’s the Managed Float Exchange Rate SystemSolutionThis is .pdf
What’s the Managed Float Exchange Rate SystemSolutionThis is .pdfWhat’s the Managed Float Exchange Rate SystemSolutionThis is .pdf
What’s the Managed Float Exchange Rate SystemSolutionThis is .pdfanavmuthu
 
What would happen if the drain resistor RD were 100k in the common .pdf
What would happen if the drain resistor RD were 100k in the common .pdfWhat would happen if the drain resistor RD were 100k in the common .pdf
What would happen if the drain resistor RD were 100k in the common .pdfanavmuthu
 
What would be the tickersymbols that would be written out on a stat.pdf
What would be the tickersymbols that would be written out on a stat.pdfWhat would be the tickersymbols that would be written out on a stat.pdf
What would be the tickersymbols that would be written out on a stat.pdfanavmuthu
 
What year was the concept of program evaluation and rerview techniqu.pdf
What year was the concept of program evaluation and rerview techniqu.pdfWhat year was the concept of program evaluation and rerview techniqu.pdf
What year was the concept of program evaluation and rerview techniqu.pdfanavmuthu
 
What would have been the plights suffered by borrowers due to financ.pdf
What would have been the plights suffered by borrowers due to financ.pdfWhat would have been the plights suffered by borrowers due to financ.pdf
What would have been the plights suffered by borrowers due to financ.pdfanavmuthu
 
What would be a good solid thesis statement for a paper Im writing.pdf
What would be a good solid thesis statement for a paper Im writing.pdfWhat would be a good solid thesis statement for a paper Im writing.pdf
What would be a good solid thesis statement for a paper Im writing.pdfanavmuthu
 
What will the alternative hypothesis communicate if we write the fol.pdf
What will the alternative hypothesis communicate if we write the fol.pdfWhat will the alternative hypothesis communicate if we write the fol.pdf
What will the alternative hypothesis communicate if we write the fol.pdfanavmuthu
 
what you learned about IPOs and the problems that resulted from th.pdf
what you learned about IPOs and the problems that resulted from th.pdfwhat you learned about IPOs and the problems that resulted from th.pdf
what you learned about IPOs and the problems that resulted from th.pdfanavmuthu
 
What were the US governments actions to solve the 2008 financial cri.pdf
What were the US governments actions to solve the 2008 financial cri.pdfWhat were the US governments actions to solve the 2008 financial cri.pdf
What were the US governments actions to solve the 2008 financial cri.pdfanavmuthu
 
What ways do correction professionals use the social justice princip.pdf
What ways do correction professionals use the social justice princip.pdfWhat ways do correction professionals use the social justice princip.pdf
What ways do correction professionals use the social justice princip.pdfanavmuthu
 
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdf
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdfWhat was the Troubled Asset Relief Fund (TARP) originally designed t.pdf
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdfanavmuthu
 
Im about to scream if I have to do another one!!! compute the cr.pdf
Im about to scream if I have to do another one!!! compute the cr.pdfIm about to scream if I have to do another one!!! compute the cr.pdf
Im about to scream if I have to do another one!!! compute the cr.pdfanavmuthu
 
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdf
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdfIm an odd number between 250 and 700. I am divisible by 5. My tens.pdf
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdfanavmuthu
 
Illustrate the importance of societal wealth ventures, social respon.pdf
Illustrate the importance of societal wealth ventures, social respon.pdfIllustrate the importance of societal wealth ventures, social respon.pdf
Illustrate the importance of societal wealth ventures, social respon.pdfanavmuthu
 
ii. Choose the correct sentence.iii. Choose the correctsentence..pdf
ii. Choose the correct sentence.iii. Choose the correctsentence..pdfii. Choose the correct sentence.iii. Choose the correctsentence..pdf
ii. Choose the correct sentence.iii. Choose the correctsentence..pdfanavmuthu
 
ii. Choose the correct sentence.iii. Choose the correct sentence..pdf
ii. Choose the correct sentence.iii. Choose the correct sentence..pdfii. Choose the correct sentence.iii. Choose the correct sentence..pdf
ii. Choose the correct sentence.iii. Choose the correct sentence..pdfanavmuthu
 
Ignore (for simplicity) the possibility of anyone being born on Febr.pdf
Ignore (for simplicity) the possibility of anyone being born on Febr.pdfIgnore (for simplicity) the possibility of anyone being born on Febr.pdf
Ignore (for simplicity) the possibility of anyone being born on Febr.pdfanavmuthu
 
IFRS requires an impairment loss for a loan receivable to be recogni.pdf
IFRS requires an impairment loss for a loan receivable to be recogni.pdfIFRS requires an impairment loss for a loan receivable to be recogni.pdf
IFRS requires an impairment loss for a loan receivable to be recogni.pdfanavmuthu
 
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdf
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdfIf (m)  is the Euler -function, show that (m) = (2m) if and only if .pdf
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdfanavmuthu
 
If znot is in the set of C (complex numbers), show that the set {zno.pdf
If znot is in the set of C (complex numbers), show that the set {zno.pdfIf znot is in the set of C (complex numbers), show that the set {zno.pdf
If znot is in the set of C (complex numbers), show that the set {zno.pdfanavmuthu
 

More from anavmuthu (20)

What’s the Managed Float Exchange Rate SystemSolutionThis is .pdf
What’s the Managed Float Exchange Rate SystemSolutionThis is .pdfWhat’s the Managed Float Exchange Rate SystemSolutionThis is .pdf
What’s the Managed Float Exchange Rate SystemSolutionThis is .pdf
 
What would happen if the drain resistor RD were 100k in the common .pdf
What would happen if the drain resistor RD were 100k in the common .pdfWhat would happen if the drain resistor RD were 100k in the common .pdf
What would happen if the drain resistor RD were 100k in the common .pdf
 
What would be the tickersymbols that would be written out on a stat.pdf
What would be the tickersymbols that would be written out on a stat.pdfWhat would be the tickersymbols that would be written out on a stat.pdf
What would be the tickersymbols that would be written out on a stat.pdf
 
What year was the concept of program evaluation and rerview techniqu.pdf
What year was the concept of program evaluation and rerview techniqu.pdfWhat year was the concept of program evaluation and rerview techniqu.pdf
What year was the concept of program evaluation and rerview techniqu.pdf
 
What would have been the plights suffered by borrowers due to financ.pdf
What would have been the plights suffered by borrowers due to financ.pdfWhat would have been the plights suffered by borrowers due to financ.pdf
What would have been the plights suffered by borrowers due to financ.pdf
 
What would be a good solid thesis statement for a paper Im writing.pdf
What would be a good solid thesis statement for a paper Im writing.pdfWhat would be a good solid thesis statement for a paper Im writing.pdf
What would be a good solid thesis statement for a paper Im writing.pdf
 
What will the alternative hypothesis communicate if we write the fol.pdf
What will the alternative hypothesis communicate if we write the fol.pdfWhat will the alternative hypothesis communicate if we write the fol.pdf
What will the alternative hypothesis communicate if we write the fol.pdf
 
what you learned about IPOs and the problems that resulted from th.pdf
what you learned about IPOs and the problems that resulted from th.pdfwhat you learned about IPOs and the problems that resulted from th.pdf
what you learned about IPOs and the problems that resulted from th.pdf
 
What were the US governments actions to solve the 2008 financial cri.pdf
What were the US governments actions to solve the 2008 financial cri.pdfWhat were the US governments actions to solve the 2008 financial cri.pdf
What were the US governments actions to solve the 2008 financial cri.pdf
 
What ways do correction professionals use the social justice princip.pdf
What ways do correction professionals use the social justice princip.pdfWhat ways do correction professionals use the social justice princip.pdf
What ways do correction professionals use the social justice princip.pdf
 
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdf
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdfWhat was the Troubled Asset Relief Fund (TARP) originally designed t.pdf
What was the Troubled Asset Relief Fund (TARP) originally designed t.pdf
 
Im about to scream if I have to do another one!!! compute the cr.pdf
Im about to scream if I have to do another one!!! compute the cr.pdfIm about to scream if I have to do another one!!! compute the cr.pdf
Im about to scream if I have to do another one!!! compute the cr.pdf
 
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdf
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdfIm an odd number between 250 and 700. I am divisible by 5. My tens.pdf
Im an odd number between 250 and 700. I am divisible by 5. My tens.pdf
 
Illustrate the importance of societal wealth ventures, social respon.pdf
Illustrate the importance of societal wealth ventures, social respon.pdfIllustrate the importance of societal wealth ventures, social respon.pdf
Illustrate the importance of societal wealth ventures, social respon.pdf
 
ii. Choose the correct sentence.iii. Choose the correctsentence..pdf
ii. Choose the correct sentence.iii. Choose the correctsentence..pdfii. Choose the correct sentence.iii. Choose the correctsentence..pdf
ii. Choose the correct sentence.iii. Choose the correctsentence..pdf
 
ii. Choose the correct sentence.iii. Choose the correct sentence..pdf
ii. Choose the correct sentence.iii. Choose the correct sentence..pdfii. Choose the correct sentence.iii. Choose the correct sentence..pdf
ii. Choose the correct sentence.iii. Choose the correct sentence..pdf
 
Ignore (for simplicity) the possibility of anyone being born on Febr.pdf
Ignore (for simplicity) the possibility of anyone being born on Febr.pdfIgnore (for simplicity) the possibility of anyone being born on Febr.pdf
Ignore (for simplicity) the possibility of anyone being born on Febr.pdf
 
IFRS requires an impairment loss for a loan receivable to be recogni.pdf
IFRS requires an impairment loss for a loan receivable to be recogni.pdfIFRS requires an impairment loss for a loan receivable to be recogni.pdf
IFRS requires an impairment loss for a loan receivable to be recogni.pdf
 
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdf
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdfIf (m)  is the Euler -function, show that (m) = (2m) if and only if .pdf
If (m)  is the Euler -function, show that (m) = (2m) if and only if .pdf
 
If znot is in the set of C (complex numbers), show that the set {zno.pdf
If znot is in the set of C (complex numbers), show that the set {zno.pdfIf znot is in the set of C (complex numbers), show that the set {zno.pdf
If znot is in the set of C (complex numbers), show that the set {zno.pdf
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

What will be the output from the following code if the user enters 4.pdf

  • 1. What will be the output from the following code if the user enters 4. int[] list = {1, 4, 4, 2, 5, -3, 6, 2}; int toSearch = input.nextInt(); int location = -1; for(int i = 0; i < list.length; i++) { if(list[i] == toSearch) { location = i; } } System.out.print(location); Solution Program: import java.io.*; import java.util.Scanner; public class Ary { public static void main(String[] args) { int[] list = {1, 4, 4, 2, 5, -3, 6, 2}; Scanner input = new Scanner(System.in); // here we are scanning the input from the user int toSearch = input.nextInt(); int location = -1; for(int i = 0; i < list.length; i++) { if(list[i] == toSearch) { location = i; } } System.out.println(location); // here we are printing the corresponding element in the list based on user input } } //if the user enters number 4 the output of the above code is as follows Output:
  • 2. 4 2