nikhilboorla Posted February 4, 2016 Report Posted February 4, 2016 public class PositionFinder { public static void findPosition(String[] list, String term){ if (list==null || list.length==0) System.out.print("Empty array"); else{ int position=-1; for (String name: list){ if(name.compareTo(term)==0) break; position++; } System.out.print(position > 0 ? position: 0); } } public static void main(String[] args){ String[] myArray = {"Hola","Kumusta", "Hello", "Ciao"}; findPosition(myArray, "Ciao"); } } 1 - What is the output of the code? a.-1b.0c.1d.2e.32 - What would have been the output if instead of "Ciao" we had "Hola" at line 19 a.-1b.0c.1d.2e.33 - What would have been the output if instead of "Ciao" we had an empty String (e.g.;"") at line 19 a.-1b.0c.1d.2e.34 - What would have been the output if we had "String[] myArray = {};" at line 18 a.Empty arrayb.NullPointer exceptionc.ArrayOutOfBounds exceptiond.05 - What line of the program would have caused a NullPointer exception if we set myArray to {"Hola"; null} at line 18 a.19b.20c.6d.9e.10
JANASENA Posted February 4, 2016 Report Posted February 4, 2016 Nenu JAVA nerchukundamanukuntunna .... endi idi chinese bhasha la undi
LungiLingaraju Posted February 4, 2016 Report Posted February 4, 2016 easy ne kada bhaiyya ... twist lu emi levu..
KaatRaja Posted February 4, 2016 Report Posted February 4, 2016 easy ne kada bhaiyya ... twist lu emi levu.. agreed
shivakumar577 Posted February 4, 2016 Report Posted February 4, 2016 assignments post cheyakandi pls... post real time problems or interview questions
KaatRaja Posted February 4, 2016 Report Posted February 4, 2016 assignments post cheyakandi pls... post real time problems or interview questions +2
rikki Posted February 4, 2016 Report Posted February 4, 2016 evi answers otions chusko 2 0 3 Empty if(name.compareTo(term)==0) Edited: public class PositionFinder { public static void findPosition(String[] list, String term){ if (list==null || list.length==0) System.out.print("Empty array"); else{ int position=-1; for (String name: list){ if(name.compareTo(term)==0) break; position++; } System.out.print(position > 0 ? position: 0); } } public static void main(String[] args){ String[] myArray = {"Hola","Kumusta", "Hello", "Ciao"}; findPosition(myArray, "Ciao"); } } 1 - What is the output of the code? a.-1b.0c.1d.2e.32 - What would have been the output if instead of "Ciao" we had "Hola" at line 19 a.-1b.0c.1d.2e.33 - What would have been the output if instead of "Ciao" we had an empty String (e.g.;"") at line 19 a.-1b.0c.1d.2e.34 - What would have been the output if we had "String[] myArray = {};" at line 18 a.Empty arrayb.NullPointer exceptionc.ArrayOutOfBounds exceptiond.05 - What line of the program would have caused a NullPointer exception if we set myArray to {"Hola"; null} at line 18 a.19b.20c.6d.9e.10
Recommended Posts