Input
Output
public class LinearSearch { public static void main(String[] args) { // Manually assigned array size and elements int n = 5; int[] arr = {10, 20, 30, 40, 50}; int target = 30; // Simulate input prompts and values System.out.println("Enter the number of elements: " + n); System.out.println("Enter " + n + " integers:"); for (int i = 0; i < n; i++) { System.out.println(arr[i]); } System.out.println("Enter the element to search: " + target); // Perform linear search boolean found = false; int position = -1; for (int i = 0; i < n; i++) { if (arr[i] == target) { found = true; position = i; break; } } // Display result if (found) { System.out.println("Element found at index: " + position); } else { System.out.println("Element not found in the array."); } } }