Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Project: Simple_Conditions - created by borkins on 2017-03-25.
- */
- import java.util.Scanner;
- public class _16a_Numbers_0_100_toText
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int number = Integer.parseInt(scan.nextLine());
- int units = number % 10;
- int tenths = number / 10;
- String unitsEng = "";
- String tenthsEng = "";
- if (units == 0) {
- unitsEng = "zero";
- }
- else if (units == 1) {
- unitsEng = "one";
- }
- else if (units == 2) {
- unitsEng = "two";
- }
- else if (units == 3) {
- unitsEng = "three";
- }
- else if (units == 4) {
- unitsEng = "four";
- }
- else if (units == 5) {
- unitsEng = "five";
- }
- else if (units == 6) {
- unitsEng = "six";
- }
- else if (units == 7) {
- unitsEng = "seven";
- }
- else if (units == 8) {
- unitsEng = "eight";
- }
- else if (units == 9) {
- unitsEng = "nine";
- }
- if (tenths == 1)
- {
- if (units == 0) {
- tenthsEng = "ten";
- }
- else if (units == 1) {
- tenthsEng = "eleven";
- }
- else if (units == 2) {
- tenthsEng = "twelve";
- }
- else if (units == 3) {
- tenthsEng = "thirteen";
- }
- else if (units == 4) {
- tenthsEng = "fourteen";
- }
- else if (units == 5) {
- tenthsEng = "fifteen";
- }
- else if (units == 6) {
- tenthsEng = "sixteen";
- }
- else if (units == 7) {
- tenthsEng = "seventeen";
- }
- else if (units == 8) {
- tenthsEng = "eighteen";
- }
- else if (units == 9) {
- tenthsEng = "nineteen";
- }
- }
- else if (tenths == 2) {
- tenthsEng = "twenty";
- }
- else if (tenths == 3) {
- tenthsEng = "thirty";
- }
- else if (tenths == 4) {
- tenthsEng = "forty";
- }
- else if (tenths == 5) {
- tenthsEng = "fifty";
- }
- else if (tenths == 6) {
- tenthsEng = "sixty";
- }
- else if (tenths == 7) {
- tenthsEng = "seventy";
- }
- else if (tenths == 8) {
- tenthsEng = "eighty";
- }
- else if (tenths == 9) {
- tenthsEng = "ninety";
- }
- // If either conditions is true, print "invalid number".
- if (number < 0 || number > 100) {
- System.out.println("invalid number");
- }
- // In that point we are sure that the number is in the range 0..100.
- // If true, number is between 0 and 9, then print numbers: 'zero', 'one', 'two'...'nine'.
- else if (number < 10) {
- System.out.println(unitsEng);
- }
- // If number is between 10 and 19, print numbers: 'ten', 'eleven', 'twelve'...'nineteen'.
- // OR if number is between 20..99 AND the digit in the units is 0,
- // print numbers: 'twenty', 'thirty', 'forty'...'ninety'.
- else if (number < 20 || (number < 100 && units == 0)) {
- System.out.println(tenthsEng);
- }
- // If number is between 20 and 99, print the numbers with two words.
- else if (number < 100) {
- System.out.println(tenthsEng + " " + unitsEng);
- }
- // The number is 100, print 'one hundred'.
- else {
- System.out.println("one hundred");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement