FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 113   



Following program shows you how to take a number between 0 to 9 and print the word representation for that number.
In this program we get numbers between 0 to 9 from user and print word representation using if condition

import java.util.Scanner;

public class Basic9 {

    public static void main(String[] args) {

        System.out.println("Enter a number between 0 to 9:");

        Scanner in = new Scanner(System.in);
        int input = in.nextInt();

        if (input == 0) {
            System.out.println("Zero");

        } else if (input == 1) {
            System.out.println("One");

        } else if (input == 2) {
            System.out.println("Two");

        } else if (input == 3) {
            System.out.println("Three");

        } else if (input == 4) {
            System.out.println("Four");

        } else if (input == 5) {
            System.out.println("Five");

        } else if (input == 6) {
            System.out.println("Six");

        } else if (input == 7) {
            System.out.println("Seven");

        } else if (input == 8) {
            System.out.println("Eight");

        } else if (input == 9) {
            System.out.println("Nine");

        } else {
            System.out.println("We don't have word representation for that number");

        }

    }

}

Output:

Example1:

Enter a number between 0 to 9:
3
Three

Example2:

Enter a number between 0 to 9:
8
Eight

Example3:

Enter a number between 0 to 9:
-2
We don't have word representation for that number



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News