Write the program numbers into words.For example
2345==two thousand three hundred fourty five

Answers were Sorted based on User's Feedback



Write the program numbers into words.For example 2345==two thousand three hundred fourty five..

Answer / sudarshan

word is:=one
word is:=two
word is:=three
word is:=four

Is This Answer Correct ?    3 Yes 3 No

Write the program numbers into words.For example 2345==two thousand three hundred fourty five..

Answer / rajesh babu

public class NumberToWords{
static final String[] Number1 = {""," Hundrad"};
static final String[] Number2 = {"","One","Two",
"Three","Four","Five",
" Six"," Seven", "Eight"," Nine","Ten" };
String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else {
str= Number2[number % 5];
number /= 5;
}
if (number == 0) return str;
return Number2[number] + "hundred" + str;
}
public String convert(int number) {
if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + str1;
}
i++;
number /= 100;
}
while (number > 0);
return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
System.out.println("words is :=" + num.convert(1));
System.out.println("words is :=" + num.convert(2));
System.out.println("words is :=" + num.convert(3));
System.out.println("words is :=" + num.convert(4));
}
}

Is This Answer Correct ?    4 Yes 13 No

Post New Answer

More Core Java Interview Questions

Can you sort a string in java?

0 Answers  


How can we create an immutable class in java?

0 Answers  


Which is better singleton or static class?

0 Answers  


How many bytes are there?

0 Answers  


what is AWT

3 Answers  






what is multitherading

3 Answers   Tech Mahindra,


What is the difference between this() and super() in java?

0 Answers  


What is sortedmap interface?

0 Answers  


How do you override a method in java?

0 Answers  


What is difference between static and final?

0 Answers  


How can I become a good programmer?

0 Answers  


Why should we create an object? what is a need of it? Apart from access members of a class i want what is a need of object what does it contain?? In normal class to access any member of thaht class we create object where as for static class we access its members using class name. what is a difference between them... thanks in advance.

1 Answers  


Categories