Using conditional if else statement print number in words

Below java code will print the integer value between 1 to 9 into words, any number other than 1 to 9 will be displayed as "OTHER".

import java.util.Scanner;

public class PrintNumberInWord {
    public static void main(String[] args) {
        System.out.println("Enter any integer number ");
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();

        if (number == 1)
            System.out.println("ONE");
        else if (number == 2)
            System.out.println("TWO");
        else if (number == 3)
            System.out.println("THREE");
        else if (number == 4)
            System.out.println("FOUR");
        else if (number == 5)
            System.out.println("FIVE");
        else if (number == 6)
            System.out.println("SIX");
        else if (number == 7)
            System.out.println("SEVEN");
        else if (number == 8)
            System.out.println("EIGHT");
        else if (number == 9)
            System.out.println("NINE");
        else
            System.out.println("OTHER");
    }
}


Output:

Enter any integer number
9
NINE

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
    or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete