Is there any thing wrong with the following code snippet? String[] data = { "abc", "def", "ghi", "jkl" };
String searchedValue = "ghi";
Int pos = 0;
Boolean found = false;
While (pos < data.length)
{
If (data[pos].equals(searchedValue) )
{
Found = true;
}
Else
{
Found = false;
}
Pos++;
}
If (found)
{
System.out.println("Found at position: " + pos) ;
}
Else
{
System.out.println("Not found") ;
}
A) There is nothing wrong.
B) There is compile-time error.
C) There is a bounds error.
D) There is a logic error.
Correct Answer:
Verified
Q23: Consider the following code snippet:
String[] data =
Q42: Select the statement that reveals the logic
Q43: Which one of the following code snippets
Q45: Consider the following code snippet:
Int cnt =
Q48: Consider the following 2-dimensional array. Select the
Q50: Consider the following code snippet. Which statement
Q51: Which one of the following is the
Q52: Why is the following method header invalid?
Q73: Which one of the following statements is
Q74: How many elements can be stored in
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents