Advertisement
Ashanmaril

Four (updated)

Sep 9th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Numbers {
  4.     public static void main(String[] args){
  5.         Scanner sc = new Scanner(System.in);
  6.         int theNum = 0;
  7.        
  8.         do{
  9.             System.out.println("Input a number between 0 and " + (words.length-1));
  10.             theNum = sc.nextInt();
  11.         }while(theNum<0 || theNum>(words.length-1));
  12.            
  13.         while(theNum != 4){
  14.             int temp = numToStr(theNum).length();
  15.             System.out.println(numToStr(theNum) + " is " + numToStr(temp));
  16.             theNum = temp;
  17.         };
  18.        
  19.         System.out.println("Four is the magic number.");
  20.        
  21.     }
  22.    
  23.     private final static String[] words = {
  24.         "Zero",
  25.         "One",
  26.         "Two",
  27.         "Three",
  28.         "Four",
  29.         "Five",
  30.         "Six",
  31.         "Seven",
  32.         "Eight",
  33.         "Nine",
  34.         "Ten",
  35.         "Eleven",
  36.         "Twelve",
  37.         "Thirteen",
  38.         "Fourteen",
  39.         "Fifteen",
  40.         "Sixteen",
  41.         "Seventeen",
  42.         "Eighteen",
  43.         "Nineteen",
  44.         "Twenty",
  45.         "Twentyone",
  46.         "Twentytwo",
  47.         "Twentythree",
  48.         "Twentyfour",
  49.         "Twentyfive",
  50.         "Twentysix",
  51.         "Twentyseven",
  52.         "Twentyeight",
  53.         "Twentynine",
  54.         "Thirty",
  55.         "Thirtyone",
  56.         "Thirtytwo",
  57.         "Thirtythree",
  58.         "Thirtyfour",
  59.         "Thirtyfive",
  60.         "Thirtysix",
  61.         "Thirtyseven",
  62.         "Thirtyeight",
  63.         "Thirtynine",
  64.         "Forty",
  65.         "Fortyone",
  66.         "Fortytwo",
  67.         "Fortythree",
  68.         "Fortyfour",
  69.         "Fortyfive",
  70.         "Fortysix",
  71.         "Fortyseven",
  72.         "Fortyeight",
  73.         "Fortynine",
  74.         "Fifty"
  75.     };
  76.    
  77.     public static String numToStr(int num){
  78.         if(num<0 || num>words.length){
  79.             throw new RuntimeException("Invalid number");
  80.         }
  81.         return words[num];
  82.     }
  83.    
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement