Coding Exercise 12: Number in Word
2021. 3. 3. 15:19ㆍJava programming
Write a method called printNumberInWord. The method has one parameter number which is the whole number. The method needs to print "ZERO", "ONE", "TWO", ... "NINE", "OTHER" if the int parameter number is 0, 1, 2, ... 9 or other for any other number including negative numbers. You can use if-else statement or switch statement whatever is easier for you.
public class NumberInWord {
public static void printNumberInWord(int number){
switch (number){
case 0:
System.out.println("ZERO");
break;
case 1:
System.out.println("ONE");
break;
case 2:
System.out.println("TWO");
break;
case 3:
System.out.println("THREE");
break;
case 4:
System.out.println("FOUR");
break;
case 5:
System.out.println("FIVE");
break;
case 6:
System.out.println("SIX");
break;
case 7:
System.out.println("SEVEN");
break;
case 8:
System.out.println("EIGHT");
break;
case 9:
System.out.println("NINE");
break;
default:
System.out.println("OTHER");
}
}
}
Having learnt switch statement, it enables me to make if-else statements in consise form particularly with great deals of else options.
Quite useful tool added to my skills to handle coding issues.
'Java programming' 카테고리의 다른 글
Coding Exercise 14: Sum Odd (0) | 2021.03.06 |
---|---|
Coding Exercise 13: Number Of Days in Month (0) | 2021.03.03 |
Coding Exercise 11: Playing Cat (0) | 2021.03.02 |
Coding Exercise 10: Equality Printer (0) | 2021.03.01 |
Coding Exercise 9: Minutes To Years and Days Calculator (0) | 2021.02.27 |