Solved

Is There Any Thing Wrong with the Following Code Snippet

Question 103

Multiple Choice

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:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions