how can i take the inputs from users in java program?

Answers were Sorted based on User's Feedback



how can i take the inputs from users in java program?..

Answer / dilshad

there r 2 ways to give the input ,


one is from command-line argument at run time.......


and the another one is to use readLine method of
DataInputStream class.............

Is This Answer Correct ?    33 Yes 1 No

how can i take the inputs from users in java program?..

Answer / mohammad faisal

There are two methods to input a text in java.
The first one is through command line arguments.
i.e.,At the run-time we have to pass all the inputs.
But there is a problem to the user of the program because
he is unable to get the order of the inputs.
Therefore a programmer must have to prefer the readLine
method.
The readLine method can be implemented like:
//1st method
import java.io.*;
class Program
{
public static void main(String args[])
{
String str="";
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter your name: ");
str=br.readLine();
System.out.print("You have entered: "+str);
}
}

//2nd method
import java.util.*;
class Program
{
public static void main(String args[])
{
String str="";
Scanner s=new Scanner(System.in);
//works in jdk 5&above
System.out.print("Enter your name: ");
str=s.next();
System.out.print("You entered: "+str);
}
}

Is This Answer Correct ?    18 Yes 0 No

how can i take the inputs from users in java program?..

Answer / archana

through the 1.command line arguments or trough 2.datainput
stream

Is This Answer Correct ?    8 Yes 1 No

how can i take the inputs from users in java program?..

Answer / harish189

1.DataInputStream Reader
2.BufferedInputStream Reader

Is This Answer Correct ?    6 Yes 0 No

how can i take the inputs from users in java program?..

Answer / prashant

With the help of Scanner class.

Is This Answer Correct ?    2 Yes 0 No

how can i take the inputs from users in java program?..

Answer / priyanka

int a;
a=Integer.parseInt(cin.readLine());

Is This Answer Correct ?    7 Yes 7 No

how can i take the inputs from users in java program?..

Answer / desai.ankita0422@gmail.com

using Scanner with next function

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

Can You Have Virtual Functions In Java?

0 Answers  


Can we compare two strings in java?

0 Answers  


What are parent methods and how can you call them?

2 Answers  


Is sizeof a keyword in java programming?

0 Answers  


Differentiate between == and equals().

0 Answers  






What is the main functionality of the remote reference layer?

0 Answers  


Explain a situation where finally block will not be executed?

0 Answers  


What is the difference between final, finally and finalize()?

0 Answers  


Write a java program to print fibonacci series?

0 Answers  


how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion

2 Answers   SAP Labs,


What do u mean by wrapper Class? What do u mean by Jvm... How do u change JVM for other OS? Or No need to Change ...? its like tricky

6 Answers   Accenture, EDS,


What is the argument in java?

0 Answers  


Categories