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

2 comments:

  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
  2. Nice site....Please refer this site also Our vision success!Training are focused on perfect improvement of technical skills for Freshers and working professional. Our Training classes are sure to help the trainee with COMPLETE PRACTICAL TRAINING and Real time methodologies
    Best Dot Net Training in Chennai
    Selenium Training in chennai
    Software Testing Coaching in Chennai
    Core Java Training in Chennai
    PHP Course in Chennai

    ReplyDelete