I would like to get some help on converting an integer to word. I am very new to Java, i kind of have an idea of what i think im going to be doing but need some help with it.
The code should print the words of number from 0-999 and once -1 typed in the scanner the program should stop.
Like this:
Please type a number between 0 and 999: 1
ONE
Please type a number between 0 and 999: 11
ELEVEN
Please type a number between 0 and 999: 122
ONE HUNDRED AND TWENTY TWO
Please type a number between 0 and 999: 1000
NUMBER OUT OF RANGE
Please type a number between 0 and 999: -1
Thank you for using our program
I also have to use methods to make this "Cleaner"
First of all take hundreds place digit by deviding by 100 and print corresponding number by calling method
numberToWord((number / 100), " HUNDRED");
since number / 100 would be in between 0 to 9 so it will print digit in word concatenated by HUNDRED.Now you left with two digit number for that you directly call
numberToWord((number % 100), " ");
since we are taking modulo 100 of number so it would pass two digit only.if (num > 19) {System.out.print(tens[num / 10] + " " + ones[num % 10]);}
then it will take tens place and print tens word concatenated by ones.else {System.out.print(ones[num]);}
directly prints word between 1 to 19 from the array.Sample output: