SHARE
TWEET

numberFrom0to100Text

mswi12 Aug 29th, 2017 (edited) 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Print Number 0...100 to Text
  5.  */
  6. public class numberFrom0to100 {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int number = Integer.parseInt(scanner.nextLine());
  10.         String [] ZeroToNineteen  = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
  11.                 "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  12.         String [] Tens  = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "one hundred" };
  13.         int toTens = number / 10 - 2;
  14.         int nineteen = number % 10;
  15.         if (number <= 100 && number >=0 ) {    /0,1,2.....100
  16.                 if (number < 20) {            /0,1,2.....19
  17.                     System.out.println(ZeroToNineteen[number]);
  18.                 } else if (number >= 20 && number % 10 == 0) {    // 20,30,40...100
  19.                     System.out.println(Tens[toTens]);
  20.                 } else
  21.                     {
  22.                         System.out.println(Tens[toTens] + " " + ZeroToNineteen[nineteen]);
  23.                     }
  24.  
  25.         } else {
  26.                 System.out.println("invalid number");
  27.                }
  28.  
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top