I have to call a method which is converting number to words and two others methods which are reversing and getting count of entered number and have to call both in first method but in case of number 100 it is giving output as ONE but it should give ONE ZERO ZERO.So my confusion is how to call count method in converting number method and to make give output as ONE ZERO ZERO with simple calling because I am using intelliJ and a beginner So I have to find out how to call get count method in first method which is number to word.
public static void numberToWords(int number) {
if (number == 0) {
System.out.println("Zero");
} else if (number < 0) {
System.out.println("Invalid Value");
}
int revInteger = reverse(number);
while (revInteger != 0) {
int modulus = revInteger % 10;
revInteger /= 10;
switch (modulus) {
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:
break;
}
}
}
public static int reverse(int reversedNumber) {
int revNumber = reversedNumber;
int digit = 0;
while (revNumber != 0) {
int n = revNumber % 10;
digit = digit * 10 + n;
revNumber /= 10;
}
return digit;
}
public static int getDigitCount(int number) {
int count = 0;
if (number > 0) {
while (number != 0) {
number /= 10;
++count;
}
return count;
} else if (number == 0) {
return 1;
}
return -1;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…