Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OnetoHundred {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int a = Integer.parseInt(scanner.nextLine());
- int b = 0;
- int c = 0;
- String bword = "";
- String cword = "";
- if (a < 0 || a > 100) {
- System.out.println("invalid number");
- } else if (a == 0) {
- System.out.println("zero");
- } else if (a == 100) {
- System.out.println("one hundred");
- } else if (a > 0 && a < 20) {
- if (a == 1) {
- System.out.println("one");
- }
- if (a == 2) {
- System.out.println("two");
- }
- if (a == 3) {
- System.out.println("three");
- }
- if (a == 4) {
- System.out.println("four");
- }
- if (a == 5) {
- System.out.println("five");
- }
- if (a == 6) {
- System.out.println("six");
- }
- if (a == 7) {
- System.out.println("seven");
- }
- if (a == 8) {
- System.out.println("eight");
- }
- if (a == 9) {
- System.out.println("nine");
- }
- if (a == 10) {
- System.out.println("ten");
- }
- if (a == 11) {
- System.out.println("eleven");
- }
- if (a == 12) {
- System.out.println("twelve");
- }
- if (a == 13) {
- System.out.println("thirteen");
- }
- if (a == 14) {
- System.out.println("fourteen");
- }
- if (a == 15) {
- System.out.println("fifteen");
- }
- if (a == 16) {
- System.out.println("sixteen");
- }
- if (a == 17) {
- System.out.println("seventeen");
- }
- if (a == 18) {
- System.out.println("eighteen");
- }
- if (a == 19) {
- System.out.println("nineteen");
- }
- } else if (a > 19 && a < 100) {
- b = a / 10;
- c = a % 10;
- if (b == 2)
- bword = "twenty";
- if (b == 3)
- bword = "thirty";
- if (b == 4)
- bword = "forty";
- if (b == 5)
- bword = "fifty";
- if (b == 6)
- bword = "sixty";
- if (b == 7)
- bword = "seventy";
- if (b == 8)
- bword = "eighty";
- if (b == 9)
- bword = "ninety";
- if (c == 1)
- cword = "one";
- if (c == 2)
- cword = "two";
- if (c == 3)
- cword = "three";
- if (c == 4)
- cword = "four";
- if (c == 5)
- cword = "five";
- if (c == 6)
- cword = "six";
- if (c == 7)
- cword = "seven";
- if (c == 8)
- cword = "eight";
- if (c == 9)
- cword = "nine";
- if (c == 0) {
- System.out.println(bword);
- } else System.out.println(bword + " " + cword);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement