0
How To Accept A Value In Java After System.out.println?
JAVA
8 Respuestas
+ 3
import java.io.*;
public class Program
{
public static void main(String[] args) {
String playerName;
StringBuffer buffer = new StringBuffer();
BufferedReader nameReader = new BufferedReader(new InputStreamReader(System.in));
playerName = null;
System.out.println("Insert player name:");
try
{
playerName = nameReader.readLine();
buffer.append(playerName);
}
catch(Exception ex)
{
ex.printStackTrace();
}
System.out.println("Your name is "+playerName+" ,right?");
}
}
+ 1
import java.util.Scanner;
System.out.println("type a value");
Scanner scan = new Scanner(System.in);
String value = scan.nextLine();
System.out.println(value)
+ 1
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
System.out.println("Please enter your name");
Scanner name= new Scanner(System.in);
String nam;
nam=name.nextLine();
System.out.println("Your name is "+nam);
}
}
You have to use Scanner class(there are other class also) to take input. It is written in basic concepts of java please complete tutorial.
+ 1
He wanted to know how to take input, it does not matter which data type or what is length of input.
0
using Scanner.next() would actualy only get the first word of the input
0
Just saying that nextLine would be more apropiated in your example
0
In InputStreamReader And BufferedReader?
0
In InputStreamReader?