Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on user input in java within the Java forums, part of the Software Development category; how we can use the user input in java....
|
|||||||
|
|||
|
plz tell me the error:-
class input { public static void main(String args[]); Throws IOException; { int i; String str; BufferReaderbr=newBufferReader(newInputstreamReader(System.in)); System.out.println("enter name"); str = br.Readline() System.out.println(str); } |
|
|||
|
Re: user input in java
this is santhosh
to perform input operation in java either we can user iostreams or some predefined classes exist in java.util.* package and those util package classes like Random,Scanner(possible to use only from jdk 1.5) etc i am demonstrating a simple example with Scanner class in Scanner class we have diffrent methods exist for reading different type of values. for integer nextInt(), for double nextDouble() etc. Example: import java.util.*; class InputDemo { public static void main(String args[]) { Scanner in=new Scanner(System.in); int a,b; System.out.println("enter a,b values : "); a=in.nextInt(); b=in.nextInt(); System.out.println("a = "+a+"\tb = "+b); } } and one more way to perform input operation is Command line arguments but every command line argument is treated as String object but to work with integers,float values we have to wrap the String objects into integer,float etc using Wrapper classes like Integer,Float etc defined in java.lang packages |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to see what work the user had already done by the user on remote desktop | Rajanikanth B.V | Windows | 2 | 01-20-2009 04:34 AM |
| accepting input | lokeshwarigajendrakumar | MainFrame | 0 | 05-06-2008 03:49 AM |
| Input and output | AnnieL4864 | VB.NET | 1 | 11-20-2007 05:12 AM |
| How can I create web part with user input box | Husain | VB.NET | 0 | 06-06-2007 08:46 PM |
| How to Clear Input Buffer | blenda | C and C++ | 1 | 11-12-2006 03:08 PM |