Hi guys here is the solution cheers :) keep supporting by clicking on ads :p
import java.util.Scanner;
class Solution {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
int n=sc.nextInt();
int n1=n,n2=n;
int b=n1%10,a=n2/10; // n1/10 means last digit is removed and n2%10 means last digit by modulus
String[] single_digits = new String[]{"zero","one","two","three","four","five", "six","seven","eight","nine"};
String[] two_digits = new String[]{"","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen", "nineteen"};
String[] tens_multiple = new String[]{"","","twenty","thirty","forty","fifty","sixty", "seventy","eighty","ninety"};
if(a==1)
{
System.out.println(two_digits[b+1]);
}
else if(b==0)
System.out.println(tens_multiple[a]);
else
System.out.println(tens_multiple[a]+"-"+single_digits[b]);
}//main
}
Output:
enter the number3
-three
45
forty-five
90
ninety
Comments
Post a Comment