Advertisement
martyz

NumberTo100withWords

Aug 7th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Losh17 on 5.8.2017 г..
  5.  */
  6. public class NumbersTo100withWords {
  7.     public static void main(String[] args) {
  8.         Scanner console = new Scanner(System.in);
  9.         Integer num = Integer.parseInt(console.nextLine());
  10.         String[] arr0to13 = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
  11.         String[] specialArr = new String[]{"none", "none", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  12.  
  13.         //1 to 19
  14.         if (num >= 0 && num <= 19) {
  15.             System.out.println(arr0to13[num]);
  16.         }
  17.         //20 to 100
  18.         if (num >= 20 &&  num <= 100){
  19.             if (num == 100) {
  20.                 System.out.println("one hundred"); return;
  21.             }
  22.             if (num % 10 == 0) {
  23.                 System.out.println(specialArr[num / 10]);
  24.             } else {
  25.                 System.out.println(specialArr[num / 10] + " " + arr0to13[num % 10]);
  26.             }
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement