You are given a partially completed Java program that converts a numeric value (1 or 2) into its equivalent word ("One" or "Two"). If an invalid value is entered, the program should print "Invalid number." However, some code blocks are missing. Your task is to fill the blanks in the Java code to ensure that the program functions as described.
Multiple conditions: switch
Converting numerical values into words
Report a typo
Fill in the gaps with the relevant elements
public class Main {
public static void main(String[] args) {
int number = 2;
String numberInWords;
(number) {
1:
numberInWords = "One";
break;
case 2:
numberInWords = "Two";
;
:
numberInWords = "Invalid number";
break;
}
System.out.println(numberInWords);
}
}Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.