- 1
Can you help me?
An online electronics store has 5 product categories - PCs, Notebooks, Tablets, Phones, and Аccessories. The program you are given declares an array and stores that types into it. Write a program to take N number as input and output the element of the array with N index. If the index is out of range, program should output "Wrong Option".
7 Respostas
+ 11
import java.util.Scanner;
//Please Subscribe to My Youtube Channel
//Channel Name: Fazal Tuts4U
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", "Аccessories"};
try {
System.out.println(categories[choice]);
} catch(Exception e) {
System.out.println("Wrong Option");
}
}
}
+ 4
You missed else statement.
BTW, try this
https://code.sololearn.com/c4CfF5T9lqV0/?ref=app
0
Thank you
0
import 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", "Аccessories"};
//complete the code
try {
System.out.println(categories[choice]);
} catch(Exception e) {
System.out.println("Wrong Option");
}
}
}
0
import 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", "Аccessories"};
try {
System.out.println(categories[choice]);
} catch(Exception e) {
System.out.println("Wrong Option");
}
}
}
0
A local electronics shop has a great deal for notebooks.
You want to buy as many notebooks as you can afford. For that, you need to calculate how many notebooks you can buy with the amount in your bank account and how much money will be left over.
The given code includes comments as instructions for two tasks you need to complete.
Follow the instructions to solve this code coach!
- 1
https://code.sololearn.com/c53a3a3a94A1
i know i cheated a little, but idk how to use that catch block