In Java
Write a program which includes a method named numToText(). It has a single parameter. The method takes digit (0-9), and depending on the input, returns the digit as a word (in English). Output the result from main().

Respuesta :

tonb

Answer:

class Main {

 public static String numToText(int digit) {

   String[] numbers = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

   return numbers[digit % 10];

 }

 public static void main(String[] args) {

   for(int i=0; i<10; i++) {

     System.out.println(i+" = "+numToText(i));

   }

 }

}

Explanation:

I clip the input on being 0-9 by taking it modulo 10. You could also create error handling for that if desired.

ACCESS MORE
EDU ACCESS
Universidad de Mexico