0

Can anyone tell me the correct code

PYTHON intermediate course >> file handling >> this code showing error it can't satisfy the test caseimport java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int choice = scanner.nextInt(); String[] categories = {"PCs", "Notebooks", "Tablets", "Phones","Accessories"}; try { // Check if the input choice is within the valid range if (choice >= 0 && choice < categories.length) { System.out.println(categories[choice]); } else { // Out of bounds index System.out.println("Wrong Option\n"); } } catch (Exception e) { System.out.println("An error occurred"); // Capital 'E' in Exception } } } Tell me plz

24th Sep 2024, 1:04 PM
BHANUTEJA
BHANUTEJA - avatar
3 odpowiedzi
+ 3
BHANUTEJA the Python interpreter probably hasn't studied Java language. I am sure it is very confused by this code.
24th Sep 2024, 2:09 PM
Brian
Brian - avatar
+ 1
python: import java.util.Scanner; ?? wow *.* this is really new to me....
24th Sep 2024, 1:24 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 1
anyways, you don't need the if-else statement: delete the if line delete the } else { line but keep the else's output (without \n) and replace the existing output in the catch block.... if you are asking ChatGPT or similar AI tool to solve your problem, ask it to fix own bugs as well with explaining the code :-)
24th Sep 2024, 1:36 PM
Mihaly Nyilas
Mihaly Nyilas - avatar