Online Shopping Categories
This program simulates online shopping categories.
Problem Statement
Write a Java program that prints shopping category based on choice.
Source Code
| 1 | public class ShoppingCategories { |
| 2 | public static void main(String[] args) { |
| 3 | int choice = 2; |
| 4 | switch(choice) { |
| 5 | case 1: System.out.println("Electronics - Eduinq"); break; |
| 6 | case 2: System.out.println("Clothing - Eduinq"); break; |
| 7 | case 3: System.out.println("Groceries - Eduinq"); break; |
| 8 | default: System.out.println("Invalid choice - Eduinq"); |
| 9 | } |
| 10 | } |
| 11 | } |
Program Output
Clothing - Eduinq
Explanation
The program uses switch to simulate shopping categories. Each case corresponds to a category. If the choice matches, the program prints the selected category. Shows how switch can simulate shopping categories.