Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_10 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int input = Integer.parseInt(scanner.nextLine());
- String num0 = "zero";
- String num1 = "one";
- String num2 = "two";
- String num3 = "three";
- String num4 = "four";
- String num5 = "five";
- String num6 = "six";
- String num7 = "seven";
- String num8 = "eight";
- String num9 = "nine";
- String num10 = "ten";
- String num11 = "eleven";
- String num12 = "twelve";
- String num13 = "thirteen";
- String num14 = "fourteen";
- String num15 = "fifteen";
- String num16 = "sixteen";
- String num17 = "seventeen";
- String num18 = "eighteen";
- String num19 = "nineteen";
- String num20 = "twenty";
- String num30 = "thirty";
- String num40 = "forty";
- String num50 = "fifty";
- String num60 = "sixty";
- String num70 = "seventy";
- String num80 = "eighty";
- String num90 = "ninety";
- String num100 = " hundred";
- String nameNum = "";
- int first = 0;
- int second = 0;
- if (input >= 100) {
- first = input / 100;
- switch (first) {
- case 1:
- nameNum = num1 + num100;
- break;
- case 2:
- nameNum = num2 + num100;
- break;
- case 3:
- nameNum = num3 + num100;
- break;
- case 4:
- nameNum = num4 + num100;
- break;
- case 5:
- nameNum = num5 + num100;
- break;
- case 6:
- nameNum = num6 + num100;
- break;
- case 7:
- nameNum = num7 + num100;
- break;
- case 8:
- nameNum = num8 + num100;
- break;
- case 9:
- nameNum = num9 + num100;
- break;
- }
- input = input % 100;
- if (input > 0) {
- nameNum += " and ";
- }
- }
- if (input >= 10 && input < 20) {
- switch (input) {
- case 10:
- nameNum += num10;
- break;
- case 11:
- nameNum += num11;
- break;
- case 12:
- nameNum += num12;
- break;
- case 13:
- nameNum += num13;
- break;
- case 14:
- nameNum += num14;
- break;
- case 15:
- nameNum += num15;
- break;
- case 16:
- nameNum += num16;
- break;
- case 17:
- nameNum += num17;
- break;
- case 18:
- nameNum += num18;
- break;
- case 19:
- nameNum += num19;
- break;
- }
- }
- if (input >= 20) {
- second = input / 10;
- switch (second) {
- case 2:
- nameNum += num20;
- break;
- case 3:
- nameNum += num30;
- break;
- case 4:
- nameNum += num40;
- break;
- case 5:
- nameNum += num50;
- break;
- case 6:
- nameNum += num60;
- break;
- case 7:
- nameNum += num70;
- break;
- case 8:
- nameNum += num80;
- break;
- case 9:
- nameNum += num90;
- break;
- }
- input = input % 10;
- if (input > 0) {
- nameNum += " ";
- }
- }
- if (input <= 9) {
- switch (input) {
- case 1:
- nameNum += num1;
- break;
- case 2:
- nameNum += num2;
- break;
- case 3:
- nameNum += num3;
- break;
- case 4:
- nameNum += num4;
- break;
- case 5:
- nameNum += num5;
- break;
- case 6:
- nameNum += num6;
- break;
- case 7:
- nameNum += num7;
- break;
- case 8:
- nameNum += num8;
- break;
- case 9:
- nameNum += num9;
- break;
- }
- if (!(first > 0) && !(second > 0) && input == 0) {
- nameNum += num0;
- }
- }
- System.out.println(nameNum.substring(0,1).toUpperCase() + nameNum.substring(1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement