Java intermediate -> exceptions handling problem
Import java.util.Scanner; public class Main { public static void main(String[] args) { // Declare and initialize the product categories array String[] categories = {"PCs", "Notebooks", "Tablets", "Phones", "Accessories"}; // Create a Scanner object to take input from the user Scanner scanner = new Scanner(System.in); // Take the index as input int n = scanner.nextInt(); try { // Try to access the element at the given index System.out.println(categories[n]); } catch (ArrayIndexOutOfBoundsException e) { // If an exception occurs (index out of bounds), print "Wrong Option" System.out.println("Wrong Option"); } } } The above code is not satisfying test cases. Can anyone tell me the correct code plz It is a bug 🐛