Results 1 to 5 of 5
  1. #1
    imanoob is offline Member
    Join Date
    Oct 2013
    Posts
    8
    Rep Power
    0

    Default SOLVED: Need example of input & output including hasNextLong method

    Hi,

    Could someone please give me an example of an input & output using hasNextLong? I am not sure how to use it.
    For example: ask user to input something using scanner, and then check if it's a long.


    Thanks!
    Last edited by imanoob; 10-17-2013 at 05:04 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Need example of input & output including hasNextLong method

    It is amazing how resilient computers are. If you write incorrect code, compile and run it the computer will not explode. So, go to the API and read about the Scanner class and what its methods do. Attempt to write a small test program and run it. If you get stuck post your code here, include full and exact error messages and ask a specific question.

  3. #3
    imanoob is offline Member
    Join Date
    Oct 2013
    Posts
    8
    Rep Power
    0

    Default Re: Need example of input & output including hasNextLong method

    To anyone who needs an example of how to use the hasNextLong method:

    Scanner in = new Scanner(System.in);
    System.out.println("Enter a number: ");
    if (!in.hasNextLong()) { //if not long
    System.out.println("Not a long.");
    in.next();
    }
    else { //else long
    long creditNum = in.nextLong();
    System.out.println("Long: " +creditNum);
    }

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Need example of input & output including hasNextLong method

    See! You didn't need anyone to give you the code after all. You just learnt something all by yourself. Well done.

  5. #5
    imanoob is offline Member
    Join Date
    Oct 2013
    Posts
    8
    Rep Power
    0

    Default Re: Need example of input & output including hasNextLong method

    Thanks.

Similar Threads

  1. How do you do in an input and then get an output?
    By coding in forum New To Java
    Replies: 2
    Last Post: 01-27-2013, 01:41 AM
  2. Input/Output without java.io
    By Arka in forum New To Java
    Replies: 2
    Last Post: 07-18-2012, 09:32 AM
  3. Input Output stream
    By kazuhiko in forum Networking
    Replies: 13
    Last Post: 03-15-2012, 04:43 PM
  4. Input/ output file
    By 3MAD in forum New To Java
    Replies: 1
    Last Post: 04-15-2011, 12:59 PM
  5. File input output
    By edcaru in forum New To Java
    Replies: 5
    Last Post: 12-19-2010, 05:52 PM

Tags for this Thread

Posting Permissions

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