Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How would you read number or a letter from this input

    System.out.println("Enter the first number or X to end the input: ");

    double numberEntered = keyboard.nextDouble();

    while (numberEntered != 'x')
    {
    System.out.println("You entered a number");
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Read it in using nextLine. That will return a string. You can then check if the string is X, and if its not attempt to cast to a double using Double.parseDouble.

  • Users who have thanked Fou-Lu for this post:

    sabi (10-26-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •