mercredi 26 avril 2017

Java Beginner logic error help needed

i apologize in advance for my post. I decided to register tonight and this is my first post.

A little background about the question.

i am doing a little java project, where i need to take a name from user input, which is saved in a variable. the variable value must then display on the output.

my question is. how is it done in java, using the (if) keyword, to use with my code to create a if statement that voids my simple i_PlayerName method of any logic error.

to be more specific, how can i make sure that my program will only accept a string value, and if another data type is entered, a output message will be displayed " user input not accepted ".

lastly, what is this procedure called?

Thankyou all :)

keep on coding the code.

    public void i_PlayerName() {

        String playerName;

        Scanner i_playerName = new Scanner(System.in);
        System.out.println("ENTER YOUR SHIP NAME");
        playerName = i_playerName.nextLine();
        System.out.println("Your vessel has been named " + playerName);

}

Aucun commentaire:

Enregistrer un commentaire