Java assignment 09: Selecting basketball players

Java Assignments   Green = Easy,  Blue = Normal,  Red = Hard
 01   02   03   04   05   06   07   08   09   By title 

Write a simple program that allows users to insert the age and the height of
new basketball players. If the age of the player is between 16 and 30 years
and his height is 180 or higher, your program should write a message that the player is selected otherwise the player is rejected as shown below.

Insert the age: 28
Insert the height: 181
The player is selected


Java assignment 09: Selecting basketball players

Level: Normal


import java.util.Scanner;

public class Basketball
  public void acceptance(int age, int height)
    if(age > 16 && age < 30 && height >= 180)
      System.out.println("The player is selected");
      System.out.println("The player is rejected");
  public static void main(String[] args)
    Scanner input = new Scanner(;
    System.out.print("Insert the age: ");
    // the age inserted by the user
    int age = input.nextInt();
    System.out.print("Insert the height: ");
    // the height inserted by the user
    int height = input.nextInt();
    Basketball bb = new Basketball();
    // Invoke the method acceptance
    bb.acceptance(age, height);


Author: Sar Maroof


If you run the above program the following steps will happen.

  1. The program asks the user to insert the age of the player and press the enter button.
  2. The program asks the user to insert the height of the player and press the enter button.
  3. The program writes a message whether the player is selected or rejected based on the age and the height of the player.

Extra assignment

Add your own code to the program to inform the user to insert a number if the user enters symbols or letters.


If you found this difficult, you might consider reading my book Java quizmaster for beginners. It is easy to understand, organized to learn Java in 17 days and it guides you to master Java code by solving 105 quizzes and 117 assignments. This book explains each chapter properly before starting with exercises and assignments. It is available on Amazon. See inside the book here!

Please, leave your questions, feedback and suggestions in the comments below! offers a practical method to learn and improve your Java skills. It avoids unnecessary long boring theoretical explanations, but it uses many exercises and quizzes.

Sar Maroof is graduated from HBO Amsterdam "higher professional education". He is a professional computer programming teacher, gives master classes and publishes technical articles. His experience with developing software started from 2001 and he has worked as a software developer for several big as well as small companies and later as a freelancer. He is the author of Java quizmaster and Build a Java application in 7 days.

Books by Sar Maroof


 Subscribe to Sar Maroof's RSS feeds!
 Mail this page to a friend!
 Bookmark this page!

Leave a Reply

Your email address will not be published. Required fields are marked *