FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 465   



A simple Java program using if conditions which scans age from console and prints its Infant or Child or Adult based on the Input given

import java.util.Scanner;

public class AgesScanner {
    public static void main(String Args[]) {
        System.out.print("Enter the Age: ");
        Scanner in = new Scanner(System.in);
        int i = in.nextInt();
        in.close();
        if (i >= 0 && i <= 5) {
            System.out.println("Infant");
        } else if (i >= 6 && i <= 17) {
            System.out.println("Child");
        } else if (i >= 18) {
            System.out.println("Adult");
        } else {
            System.out.println("Invalid input");
        }
    }
}

Output

Enter the Age: 16
Child



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News