Java Program to convert a number into characters
In this program, You will learn how to convert a number into characters in java.
Number is: 3094
Three Zero Nine Four
Example: How to convert a number into characters in java.
import java.util.Scanner;
class Main {
public static void main(String args[]) {
int r, n, rev = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number:");
n = sc.nextInt();
while (n > 0) {
r = n % 10;
rev = rev * 10 + r;
n = n / 10;
}
n = rev;
System.out.print("\n");
while (n > 0) {
r = n % 10;
switch (r) {
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;
}
n = n / 10;
}
}
}
Output:
Enter a Number:34507
Three Four Five Zero Seven