how can i take the inputs from users in java program?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / archana
through the 1.command line arguments or trough 2.datainput
stream
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / desai.ankita0422@gmail.com
using Scanner with next function
| Is This Answer Correct ? | 0 Yes | 2 No |
Explain implementation and how is it different from conversion?
Explain public static void main(string args[]).
Which of the following can be referenced by a variable? A. The instance variables of a class only B. The methods of a class only C. The instance variables and methods of a class
What is string pooling concept?
I am a fresher and know core java, c languge, html, css etc if I am illegible for any job then send it on my email tatranakshay276@gmail.com
What are structs in java?
What is an iterator interface in java programming?
What is slash r?
What is the difference between Java Bean and Java Class.?
What happens if an exception is not caught?
What is method Overloading in the perspective of OOPS?
Which sorting is best in java?