Results 1 to 3 of 3
- 05-15-2012, 02:36 AM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
need help converting numbers to word
guys, I wrote this program that converts numbers to words eq: 4914 to "four thousand and nine hundred and fourteen"; however, I'm having problems with the toString method. Is not printing correctly some numbers. the functions and their return type can't be changed. I need help with the toString method that actually puts all the words together. I appreciate any help.
testerJava Code:package numberstowords; import java.util.*; public class Numbers { //getting single digit number private int getOnes() { one = value % 10; return one; } //getting tens numbers private int getTens() { ten = value % 100; ten /= 10; return ten; } //getting hundreds numbers private int getHundreds() { hundred = value % 1000; hundred /= 100; return hundred; } //getting thousands numbers private int getThousands() { thousand = value % 10000; thousand /= 1000; return thousand; } //converting and returning string of ones private String digitsToString(int one) { return SINGLE_DIGITS_WORDS[one]; } //converting and returning strings of tens and teens private String tensAndOnesToString(int ten, int one) { if(ten == 1)//if number is a teen return, else return tens { return TEEN_DIGITS_WORDS[one]; } return TEN_DIGITS_WORDS[ten-2]; } //converting and returning strings of hundreds private String hundredsToString(int hundred) { return digitsToString(hundred) + " hundred"; } private String thousandsToString(int thousand) { return digitsToString(thousand) + " thousand"; } @Override public String toString() }
Java Code:package numberstowords; import java.util.Scanner; public class Test { //array to store the word equivalent of numbers public static String[] s = new String[8]; public static void main(String[] args) { int count = 0; Scanner input = new Scanner(System.in); do { System.out.println("Enter an integer (4 digits max)--> "); int value = input.nextInt(); if(value > 0) { Numbers n = new Numbers(value); //store n.toString in an arrayList s //s[count] = n.toString(); System.out.println(n.toString()); count++; } else break; }while(true);Last edited by miatech; 05-15-2012 at 05:04 PM.
- 05-15-2012, 06:49 AM #2
Re: need help converting numbers to word
Cross posted
need help converting numbers to word in Java - Stack Overflow
need help with toString method in java program - Ubuntu Forums
Removed the OP here:
[SOLVED] having problems printing the words for 0, 100, 1000, etc - Ubuntu Forums
but it's archived by
having problems printing the words for 0, 100, 1000, etc - (how does right-aligned code look?)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-15-2012, 06:50 AM #3
Similar Threads
-
how to change numbers into word numbers?
By akeni in forum New To JavaReplies: 13Last Post: 11-18-2011, 08:46 AM -
Converting numbers to words
By Zora in forum New To JavaReplies: 2Last Post: 11-14-2011, 10:10 AM -
converting doc(ms word) to pdf
By sgl in forum New To JavaReplies: 0Last Post: 10-21-2010, 07:03 PM -
converting .pdf to .doc(microsoft word)format
By ashik03 in forum Java AppletsReplies: 1Last Post: 01-30-2010, 02:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks