I am trying to assign value to variable based on case with old Switch case it is not allowing is there any way or should i need to write initialize variable in each single case?
public static void printNumberInWord(int number){
String inWord = switch(number){
case 0 -> "ZERO";
case 1: "ONE";
break;
case 2: "TWO";
break;
case 3: "THREE";
case 4: "FOUR";
case 5: "FIVE";
case 6: "SIX";
case 7: "SEVEN";
case 8: "EIGHT";
case 9: "NINE";
default : "no Value"
};
Enchanced Switch is working though as shown in Case0
switchstatement? Your Question is not clear. Edit for clarity.String[] values = { "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE" };and address only that rangeswitchstatements andswitchexpressions. These kinds ofswitchin Java have evolved dramatically. The topic is understandably confusing.