Advertisement
miroLLL

Number0...100Text

Apr 16th, 2018
259
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None
  1. import java.util.Scanner;
  2.  
  3. public class NumberFrom0To100Text {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner input = new Scanner(System.in);
  7.  
  8.         int number = Integer.parseInt(input.nextLine());
  9.  
  10.         String[] firstTen = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",  "nine", "ten"};
  11.         String[] teens = {"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
  12.         String[] everyTenth = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  13.  
  14.         int fPosition = number / 10 - 2;
  15.         int sPosition = number % 10;
  16.  
  17.         if (number >= 0 && number <= 10){
  18.  
  19.             System.out.println(firstTen[number]);
  20.  
  21.         } else if (number > 10 && number <= 19) {
  22.  
  23.             System.out.println(teens[number - 11]);
  24.  
  25.         } else if (number % 10 == 0 && number != 100) {
  26.  
  27.             System.out.println(everyTenth[fPosition]);
  28.  
  29.         } else if (number > 20 && number <= 99) {
  30.  
  31.             System.out.printf("%s %s", everyTenth[fPosition], firstTen[sPosition]);
  32.  
  33.         } else if (number == 100) {
  34.  
  35.             System.out.println("one hundred");
  36.  
  37.         } else {
  38.  
  39.             System.out.println("invalid number");
  40.         }
  41.     }
  42. }
Advertisement
RAW Paste Data Copied
Advertisement