Advertisement
veronikaaa86

0 to 100

Jan 29th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.02 KB | None | 0 0
  1. package SimpleCalculation;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Demo {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int num = Integer.parseInt(scanner.nextLine());
  10.         int firstNum = num / 10;  
  11.         int secondNum = num % 10;
  12.         int bothNum = num;
  13.  
  14.         String secondWord = "";
  15.         String firstWord = "";
  16.         String bothWord = "";
  17.  
  18.         if (secondNum == 0) {
  19.             secondWord = "zero";
  20.         } else if (secondNum == 1) {
  21.             secondWord = "one";
  22.         } else if (secondNum == 2) {
  23.             secondWord = "two";
  24.         } else if (secondNum == 3) {
  25.             secondWord = "three";
  26.         } else if (secondNum == 4) {
  27.             secondWord = "four";
  28.         } else if (secondNum == 5) {
  29.             secondWord = "five";
  30.         } else if (secondNum == 6) {
  31.             secondWord = "six";
  32.         } else if (secondNum == 7) {
  33.             secondWord = "seven";
  34.         } else if (secondNum == 8) {
  35.             secondWord = "eight";
  36.         } else if (secondNum == 9) {
  37.             secondWord = "nine";
  38.         }
  39.  
  40.         if (firstNum == 2) {
  41.             firstWord = "twenty";
  42.         } else if (firstNum == 3) {
  43.             firstWord = "thirty";
  44.         } else if (firstNum == 4) {
  45.             firstWord = "forty";
  46.         } else if (firstNum == 5) {
  47.             firstWord = "fifty";
  48.         } else if (firstNum == 6) {
  49.             firstWord = "sixty";
  50.         } else if (firstNum == 7) {
  51.             firstWord = "seventy";
  52.         } else if (firstNum == 8) {
  53.             firstWord = "eighty";
  54.         } else if (firstNum == 9) {
  55.             firstWord = "ninety";
  56.         }
  57.  
  58.         if (bothNum == 10) {
  59.             bothWord = "ten";
  60.         } else if (bothNum == 11) {
  61.             bothWord = "eleven";
  62.         } else if (bothNum == 12) {
  63.             bothWord = "twelve";
  64.         } else if (bothNum == 13) {
  65.             bothWord = "thirteen";
  66.         } else if (bothNum == 14) {
  67.             bothWord = "fourteen";
  68.         } else if (bothNum == 15) {
  69.             bothWord = "fifteen";
  70.         } else if (bothNum == 16) {
  71.             bothWord = "sixteen";
  72.         } else if (bothNum == 17) {
  73.             bothWord = "seventeen";
  74.         } else if (bothNum == 18) {
  75.             bothWord = "eighteen";
  76.         } else if (bothNum == 19) {
  77.             bothWord = "nineteen";
  78.         }
  79.  
  80.         if (num >= 0 && num <= 9) {
  81.             System.out.println((secondWord));
  82.         } else if (num >= 10 && num <= 19) {
  83.             System.out.println((bothWord));
  84.         } else if (num >= 20 && num <= 100) {
  85.             if (num % 10 == 0 && num != 10 && num != 100){
  86.                 System.out.println((firstWord));
  87.             } else if (num == 100) {
  88.                 System.out.println(("one hundred"));
  89.             } else {
  90.                 System.out.println((firstWord + " " + secondWord));
  91.             }
  92.         } else {
  93.             System.out.println(("invalid number"));
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement