Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Numbers {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int theNum = 0;
- do{
- System.out.println("Input a number between 0 and " + (words.length-1));
- theNum = sc.nextInt();
- }while(theNum<0 || theNum>(words.length-1));
- while(theNum != 4){
- int temp = numToStr(theNum).length();
- System.out.println(numToStr(theNum) + " is " + numToStr(temp));
- theNum = temp;
- };
- System.out.println("Four is the magic number.");
- }
- private final static String[] words = {
- "Zero",
- "One",
- "Two",
- "Three",
- "Four",
- "Five",
- "Six",
- "Seven",
- "Eight",
- "Nine",
- "Ten",
- "Eleven",
- "Twelve",
- "Thirteen",
- "Fourteen",
- "Fifteen",
- "Sixteen",
- "Seventeen",
- "Eighteen",
- "Nineteen",
- "Twenty",
- "Twentyone",
- "Twentytwo",
- "Twentythree",
- "Twentyfour",
- "Twentyfive",
- "Twentysix",
- "Twentyseven",
- "Twentyeight",
- "Twentynine",
- "Thirty",
- "Thirtyone",
- "Thirtytwo",
- "Thirtythree",
- "Thirtyfour",
- "Thirtyfive",
- "Thirtysix",
- "Thirtyseven",
- "Thirtyeight",
- "Thirtynine",
- "Forty",
- "Fortyone",
- "Fortytwo",
- "Fortythree",
- "Fortyfour",
- "Fortyfive",
- "Fortysix",
- "Fortyseven",
- "Fortyeight",
- "Fortynine",
- "Fifty"
- };
- public static String numToStr(int num){
- if(num<0 || num>words.length){
- throw new RuntimeException("Invalid number");
- }
- return words[num];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement