0

How To Accept A Value In Java After System.out.println?

JAVA

25th Nov 2016, 3:23 AM
ERFIRE
ERFIRE - avatar
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?"); } }
27th Nov 2016, 8:57 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 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)
25th Nov 2016, 4:57 AM
Wagner Silvestre Wuchryn Martins
Wagner Silvestre Wuchryn Martins - avatar
+ 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.
25th Nov 2016, 4:59 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
He wanted to know how to take input, it does not matter which data type or what is length of input.
25th Nov 2016, 5:05 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
using Scanner.next() would actualy only get the first word of the input
25th Nov 2016, 5:03 AM
Wagner Silvestre Wuchryn Martins
Wagner Silvestre Wuchryn Martins - avatar
0
Just saying that nextLine would be more apropiated in your example
25th Nov 2016, 5:09 AM
Wagner Silvestre Wuchryn Martins
Wagner Silvestre Wuchryn Martins - avatar
0
In InputStreamReader And BufferedReader?
25th Nov 2016, 2:20 PM
ERFIRE
ERFIRE - avatar
0
In InputStreamReader?
27th Nov 2016, 8:48 AM
ERFIRE
ERFIRE - avatar