-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathNumberToSentanceArray.java
36 lines (34 loc) · 1 KB
/
NumberToSentanceArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//WAP to display the enter number in the form of sentence.
import java.util.Scanner;
public class NumberToSentanceArray{
public static String one[] = {"","One","Two","Three","Four","Five","Six",
"Seven","Eight","Nine","Ten ","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
public static String two[] = {"","","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninty"};
public static void numToWord(int n, String s)
{
if(n<20)
{
System.out.print(one[n]);
}
else
{
System.out.print(two[n/10]+one[n%10]+" ");
}
if(n!=0)
{
System.out.print(s+" ");
}
}
public static void main(String[] args)
{
NumberToSentanceArray nw = new NumberToSentanceArray();
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Number : ");
int n = sc.nextInt();
numToWord(n/10000000%100," Crore ");
numToWord(n/100000%100," Lakh ");
numToWord(n/1000%100," Thousand ");
numToWord(n/100%10," Hundred ");
numToWord(n%100," ");
}
}