Advertisement
Guest User

Untitled

a guest
Dec 29th, 2017
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Number0to100toText {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int number = Integer.parseInt(scanner.nextLine());
  8.  
  9.         if (number < 20) {
  10.             switch (number) {
  11.                 case 0: System.out.println("zero"); break;
  12.                 case 1: System.out.println("one"); break;
  13.                 case 2: System.out.println("two"); break;
  14.                 case 3: System.out.println("three"); break;
  15.                 case 4: System.out.println("four"); break;
  16.                 case 5: System.out.println("five"); break;
  17.                 case 6: System.out.println("six"); break;
  18.                 case 7: System.out.println("seven"); break;
  19.                 case 8: System.out.println("eight"); break;
  20.                 case 9: System.out.println("nine"); break;
  21.                 case 10: System.out.println("ten"); break;
  22.                 case 11: System.out.println("eleven"); break;
  23.                 case 12: System.out.println("twelve"); break;
  24.                 case 13: System.out.println("thirteen"); break;
  25.                 case 14: System.out.println("fourteen"); break;
  26.                 case 15: System.out.println("fifteen"); break;
  27.                 case 16: System.out.println("sixteen"); break;
  28.                 case 17: System.out.println("seventeen"); break;
  29.                 case 18: System.out.println("eighteen"); break;
  30.                 case 19: System.out.println("nineteen"); break;
  31.                 default: System.out.println("invalid number");
  32.             }
  33.         } else if (number < 100) {
  34.             int tens = number / 10;
  35.             int units = number % 10;
  36.             switch (tens) {
  37.                 case 2: System.out.print("twenty"); break;
  38.                 case 3: System.out.print("thirty"); break;
  39.                 case 4: System.out.print("forty"); break;
  40.                 case 5: System.out.print("fifty"); break;
  41.                 case 6: System.out.print("sixty"); break;
  42.                 case 7: System.out.print("seventy"); break;
  43.                 case 8: System.out.print("eighty"); break;
  44.                 default: System.out.print("ninety");
  45.             }
  46.             switch (units) {
  47.                 case 0: System.out.println(""); break;
  48.                 case 1: System.out.println(" one"); break;
  49.                 case 2: System.out.println(" two"); break;
  50.                 case 3: System.out.println(" three"); break;
  51.                 case 4: System.out.println(" four"); break;
  52.                 case 5: System.out.println(" five"); break;
  53.                 case 6: System.out.println(" six"); break;
  54.                 case 7: System.out.println(" seven"); break;
  55.                 case 8: System.out.println(" eight"); break;
  56.                 default: System.out.println(" nine");
  57.             }
  58.         } else if (number == 100) {
  59.             System.out.println("one hundred");
  60.         } else {
  61.             System.out.println("invalid number");
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement