Why String inputting is not working in my code? Please try to solve for me.
I have tried Character variable instead of String but no use. I cut the whole sentence inputting to the next line of Scanner declaration and it works. But I don't know why. If you know, please tell me. Code Playground Link: https://code.sololearn.com/cn0eiGOs2QRv/#java import java.util.Scanner; public class LinearSearch { public static void main(String[] args){ Scanner scan = new Scanner(System.in); // System.out.print("Enter dimention of array: "); // int input1 = scan.nextInt(); System.out.print("Enter array size:"); int input2 = scan.nextInt(); int[] arr = new int[input2]; for (int i = 0; i<arr.length; i++){ System.out.print("Enter a number to the array: "); arr[i] = scan.nextInt(); } int search; System.out.print("Do you want to find a number? [Y/N]"); String some = scan.nextLine(); if(some.equals("Y") || some.equals("y")){ System.out.print("Enter a number to find in the array: "); search = scan.nextInt(); while(some.equals("Y") || some.equals("y")) { for (int i = 0; i < arr.length; i++) { if (arr[i] == search) { System.out.println("Your number is at " + i); System.out.print("Do you want to find again?"); some = scan.nextLine(); break; } else if (i == arr.length-1) { System.out.println("Sorry. Your number is not in the array."); System.out.print("Do you want to find again?"); some = scan.nextLine(); break; }else { continue; } } } } } }