Results 1 to 5 of 5

Thread: Java Input

  1. #1
    Jathu is offline Member
    Join Date
    Mar 2011
    Location
    Toronto, Canada
    Posts
    3
    Rep Power
    0

    Smile Java Input

    Hey there I am completely new to Java programming so please do not make any jokes about my simple question :P (but I am a master of HTML, CSS and Javascript :D)

    In school we are using Ready To Program to learn Java and so we use a hsa.console to run the programs.

    In ready we do the following to get the input from users:

    String name = c.readLine();
    String name = c.readString();
    int age = c.readInt();

    ...and so on.

    However I currently downloaded eclipse (On my mac if that helps) to do some more advanced Java programming outside of school. However I found out that it is much different from Ready.

    For one we were able to so c.println(); in Ready where as in Eclipse we would have to do System.out.println();

    So I was just wondering if anyone can help me to get input from Strings, Int, Doubles and etc. Thanks! :)

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

    Default

    You can still use the hsa package in Eclipse. You just have to inlcude it in your project. How to do that is an Eclipse question and not Java. Either read about it in the help or ask in an Eclipse forum.

    Or you can use the classes in the Java API. Google for an IO tutorial. One way to do it was to wrap a Bufferedreader around an InputStream. But as of Java 1.5 they introduced the Scanner class which can make getting input a bit easier. You can even use JOptionPane.

  3. #3
    Jathu is offline Member
    Join Date
    Mar 2011
    Location
    Toronto, Canada
    Posts
    3
    Rep Power
    0

    Default

    Hey Junky thanks for the reply!

    The reason I do not want to use a hsa console is for the fact that it is not a standard (as my teacher told me).

    However I Googled the scanner method and it worked! :D

    import java.util.*;

    Scanner input = new Scanner(System.in);

    String name = input.next();

    Thanks a lot! :D

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

    Default

    Just remember to read about all the methods and what they do. If input was "Fred Flintstone" your code would only return "Fred".

  5. #5
    Jathu is offline Member
    Join Date
    Mar 2011
    Location
    Toronto, Canada
    Posts
    3
    Rep Power
    0

    Default

    Oh this was one of the problems I encountered in hsa: c.readString() and c.readLine().

    I will look more into this, again thanks :)

Similar Threads

  1. Java Sound input port
    By omar.nus in forum New To Java
    Replies: 0
    Last Post: 10-19-2009, 06:01 AM
  2. Input technique for unknown lines of input
    By ducreative in forum New To Java
    Replies: 16
    Last Post: 09-23-2009, 10:26 AM
  3. Input redirection in Java
    By freephoneid in forum Advanced Java
    Replies: 6
    Last Post: 05-08-2009, 04:20 AM
  4. New to java, need a little help with array input
    By black06vfr in forum New To Java
    Replies: 11
    Last Post: 04-29-2009, 06:46 PM
  5. how to take input and verify input in Java programs
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-21-2007, 09:46 AM

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
  •