Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem10 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String number = sc.nextLine();
- int i = Integer.parseInt(number);
- String[] oneDigit = {"Zero", "one", "two", "three","four", "five", "six", "seven","eight", "nine","ten" };
- String[] tens = {"eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen","eighteen", "nineteen"};
- String[] tens2 = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
- String output = "";
- int temp;
- char tempNum1;
- char tempNum2;
- char tempNum3;
- String upperCase;
- if (i >= 0 && i <= 10) {
- output = oneDigit[i];
- upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
- System.out.println(upperCase);
- } else if (i > 10 && i < 20) {
- output = tens[i - 11];
- upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
- System.out.println(upperCase);
- } else if (i / 100 > 0) {
- tempNum1 = number.charAt(0);
- int num1 = Integer.parseInt(String.valueOf(tempNum1));
- tempNum2 = number.charAt(1);
- int num2 = Integer.parseInt(String.valueOf(tempNum2));
- tempNum3 = number.charAt(2);
- int num3 = Integer.parseInt(String.valueOf(tempNum3));
- if (num2 > 0 && num3 > 0) {
- output = oneDigit[num1] + " " + "hundred" + " " + tens2[num2 - 2] + " " + oneDigit[num3];
- } else if (num2 == 0 && num3 == 0) {
- output = oneDigit[num1] + " " + "hundred" ;
- } else if (num2 == 0 && num3 > 0) {
- output = oneDigit[num1] + " " + "hundred" + " " + "and" + " "+ oneDigit[num3];
- } else {
- output = oneDigit[num1] + " " + "hundred" + " " + "and" + " " + tens2[num2 - 2];
- }
- upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
- System.out.println(upperCase);
- } else if (i / 10 > 0) {
- tempNum1 = number.charAt(0);
- int num1 = Integer.parseInt(String.valueOf(tempNum1));
- tempNum2 = number.charAt(1);
- int num2 = Integer.parseInt(String.valueOf(tempNum2));
- if (num2 > 0) {
- output = tens2[num1 - 2] + " " + oneDigit[num2];
- } else {
- output = tens2[num1 - 2];
- }
- upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
- System.out.println(upperCase);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement