Here’s a simple Java program that converts a given integer into its word representation, printing each digit’s corresponding English word in the same order.
β Java Program: Convert Number to Words
import java.util.Scanner;
public class NumberToWords {
// Array to store words for digits 0-9
static String[] digitWords = {
“zero”, “one”, “two”, “three”, “four”,
“five”, “six”, “seven”, “eight”, “nine”
};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input number
System.out.print(“Enter a number: “);
int num = scanner.nextInt();
// Convert to string to access each digit
String numStr = String.valueOf(num);
// Loop and print each digit’s word
for (int i = 0; i < numStr.length(); i++) {
char ch = numStr.charAt(i);
// Convert character to digit
int digit = Character.getNumericValue(ch);
// Print the word
System.out.print(digitWords[digit] + ” “);
}
System.out.println(); // For clean output
}
}
β Sample Input:215
β Output:two one five