I am a college freshman who's studying programming, so apparently, I'm new to this, but I'm already at the part of switch statements.
The goal of my program is to be like a dictionary. When user enters the term, the program should enter its meaning. But my program keeps printing the default
. What do you think am I missing? Here's my code:
Scanner scn = new Scanner(System.in);
System.out.print("Enter the term:");
String term = scn.nextLine();
switch(term) {
case "Programming":
System.out.println("It is the process of creating a set of instructions to tell the computer how to do a task.");
break;
case "Java":
System.out.println("A popular high-level and object-oriented programming language developed by Sun Microsystems in 1995 and now, owned by Oracle.");
break;
case "print":
System.out.println("A method in Java that is used to display a text on the console.");
break;
case "scanner":
System.out.println("It is used to get an input data from the user, and found in the java.util package.");
break;
case "packages":
System.out.println("It organizes Java classes into namespaces, providing a unique namespace for each type it contains.");
break;
case "IDE":
System.out.println("also known as Integrated Development Environment, a software app that enables us to write & debug programs more easily.");
break;
case "switch":
System.out.println("Unlike conditionals, these statements only checks equality and only works strings, char, int and enums.");
break;
case "function":
System.out.println("A block of organized, reusable code that is used to perform a single, related action.");
break;
case "Conditional Statements":
System.out.println("It allows a program to take action based on the given condition.");
break;
case "IF-statements":
System.out.println("It is one of the conditional statement that handles one conditional expression. It either does SOMETHING or NOTHING.");
break;
default:
System.out.println("Sorry, we don't have any information about that.");
}
scn.close();
Sorry, if it's a lengthy program, I want to make it ten items as possible. I also forgot to tell you that I tried once to remove the Scanner
and only declare the variables, the program worked (just for you to know that my program also works and print strings).
Anyway, for those who will respond, thank you very much in advance!