23. Display a number in words even with tailing 0.


package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scan=new Scanner(System.in);

System.out.println("Enter a Number");
int n=scan.nextInt();

int r;
String str="";

while(n>0)
{
r=n%10;
n=n/10;
str=str+r;

}
System.out.println(str);

char c;
for(int i=str.length()-1;i>=0;i--)
{
c=str.charAt(i);
switch(c) {
case '0':
System.out.print("Zero ");
break;
case '1':
System.out.print("One ");
break;
case '2':
System.out.print("Two ");
break;
case '3':
System.out.print("Three ");
break;
case '4':
System.out.print("Four ");
break;
case '5':
System.out.print("Five ");
break;
case '6':
System.out.print("Six ");
break;
case '7':
System.out.print("Seven ");
break;
case '8':
System.out.print("Eight ");
break;
case '9':
System.out.print("Nine ");
break;
}
}





}

} 

Enter a Number

23

32

Two Three 

Process finished with exit code 0

Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

CREATE UNIT CONVERTER APP

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees