Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Created by Losh17 on 5.8.2017 г..
- */
- public class NumbersTo100withWords {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- Integer num = Integer.parseInt(console.nextLine());
- String[] arr0to13 = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
- String[] specialArr = new String[]{"none", "none", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
- //1 to 19
- if (num >= 0 && num <= 19) {
- System.out.println(arr0to13[num]);
- }
- //20 to 100
- if (num >= 20 && num <= 100){
- if (num == 100) {
- System.out.println("one hundred"); return;
- }
- if (num % 10 == 0) {
- System.out.println(specialArr[num / 10]);
- } else {
- System.out.println(specialArr[num / 10] + " " + arr0to13[num % 10]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement