Hello guyz Just written a small code trying to make a scenario in which I get a name from user and see that the provided name is present in my array list if it is then it displays name found if not present in array it simply says name not found i haev tried it alot time but not suceeded can anyone help me out where i am doing mistake?
import java.util.Scanner;
public class Mypractice {
public static void main(String[] args) {
newthis obg = new newthis(24, 6);
Scanner obj2 = new Scanner(System.in);
String name;
String[] arr = new String[4];
arr[0] = "Usman" ;
arr[1] = "Talha" ;
arr[2] = "Mairaj" ;
arr[3] = "Kokab" ;
System.out.print("Enter a name to search :" );
name = obj2.nextLine();
int count = 0;
int wrong = 0;
for(int i=0; i<=4; i++)
{
if(name.equals(arr[i]))
{
System.out.println("Name found");
}
else
{
System.out.println("Name not found");
break;
}
}
}
}