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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java Newbie Help

    Hey I just recently started learning Java about a month ago (I've known C++ and True Basic for a couple years) and I've got a question that will probably be simple for most people to answer. I'm writing a simple application where the user is prompted to input any integer and it goes from there. Anyways I don't know how to do the input part. From what I've read it seems much harder than in C++ so I'm not really sure how to do it. Any help would be appreciated. Thanks.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    First of all you need this statement...
    Code:
    public static void main(String args[]) throws Exception
    The 'throws Exception' statement is whats needed in the main().
    Also there are different ways to accept user input. What I use mostly is this:
    Code:
    p1 = (char)System.in.read();
    Where p1 is your variable that will save the user's input. Note that you will need a System.in.read(); for each character accepted.

  • #3
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ^ If you ask me reading one char at a time is kinda doing it the hard way.
    link
    <JPM />

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by JPM
    ^ If you ask me reading one char at a time is kinda doing it the hard way.
    I was just suggesting the char because it's what I use when working with a minimal amount of input. But I agree the BufferedReader is a great way also.


  •  

    Posting Permissions

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