How can we take various inputs from user as int,char,string,float etc ?

Showing Answers 1 - 13 of 13 Answers

satheesh

  • Sep 19th, 2005
 

U can't get inputs as different datatypes u can get them as String only after getting them u can convert them using the Integer.parseInt() same for float .For char u better use a for loop and get string character by character and store iti in array.use charAt() method

Devidas Sonawane

  • Oct 27th, 2005
 

By using StringReader we access parameter as String and by type-casting  into it into (Integer.parseInt(variable_name)) int, float, char, double, long etc. U don't get parameter as primitive type use Wrapper classes.

  Was this answer useful?  Yes

Devidas Sonawane

  • Oct 27th, 2005
 

By using BufferedReader we access parameter as String and by type-casting  into it into (Integer.parseInt(variable_name)) int, float, char, double, long etc. U don't get parameter as primitive type use Wrapper classes

  Was this answer useful?  Yes

Bharathi

  • Jun 27th, 2006
 

You can take input parameters using System.in() method for all premitive datatypes.

  Was this answer useful?  Yes

sanjeeb

  • May 21st, 2007
 

Can you say how to take input parameters of any primitive type using System.in() method by giving some examples.

  Was this answer useful?  Yes

Firstly take the User input as String using the BufferedReader API.Call br.readLine();

Once you get the input Use .ValueOf method for conversion.

 
Eg:

String MyString;
BufferedReader br = ............;
MyString = br.readLine();
Integer INTVALUE = Integer.ValueOf(MyString);

  Was this answer useful?  Yes

dinesh

  • Oct 12th, 2011
 

example we get input for integer,
Scanner scan = new Scanner(System.in);
int variable_name = scan.nextInt();

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions