Results 1 to 5 of 5
Thread: Java Input
- 03-31-2011, 02:41 AM #1
Member
- Join Date
- Mar 2011
- Location
- Toronto, Canada
- Posts
- 3
- Rep Power
- 0
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! :)
- 03-31-2011, 02:54 AM #2
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.
- 03-31-2011, 03:02 AM #3
Member
- Join Date
- Mar 2011
- Location
- Toronto, Canada
- Posts
- 3
- Rep Power
- 0
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
- 03-31-2011, 03:05 AM #4
Just remember to read about all the methods and what they do. If input was "Fred Flintstone" your code would only return "Fred".
- 03-31-2011, 03:27 AM #5
Member
- Join Date
- Mar 2011
- Location
- Toronto, Canada
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Java Sound input port
By omar.nus in forum New To JavaReplies: 0Last Post: 10-19-2009, 05:01 AM -
Input technique for unknown lines of input
By ducreative in forum New To JavaReplies: 16Last Post: 09-23-2009, 09:26 AM -
Input redirection in Java
By freephoneid in forum Advanced JavaReplies: 6Last Post: 05-08-2009, 03:20 AM -
New to java, need a little help with array input
By black06vfr in forum New To JavaReplies: 11Last Post: 04-29-2009, 05:46 PM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM
Bookmarks