Enter the player name. The name must be between 1 and 6 characters in length and not begin or end with a space character. If not meet the requirement reenter the name.
import java.util.Scanner;
public class Player
{
public void acceptName()
{
System.out.println("Please enter playrname");
Scanner scanner = new Scanner(System.in);
String playerName = scanner.nextLine();
while(playerName.length() < 1 || playerName.length() > 6)
{
System.out.println("Name length over 6,Please re-enter playername");
playerName = scanner.nextLine();
}
}
}