The better way to ask for input?

Posted by Skippy on Programmers See other posts from Programmers or by Skippy
Published on 2013-10-22T09:18:55Z Indexed on 2013/10/22 10:13 UTC
Read the original article Hit count: 197

Filed under:

I am wondering which is the best way to go with java code. I need to create a class with simple prompts for input.. I have tried using both classes and cannot work out the particular benefits for each. Is this because I am still in the early stages of programming or are there situations that will occur as it becomes more complex??

import java.util.Scanner;

public class myClass
{
    Scanner stdin = new Scanner(System.in);

public String getInput(String prompt)  
 {
        System.out.print(prompt);
        return stdin.nextLine();
    }

... or

import java.io.*;

public class myClass
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
        System.out.print("Input something: ");
        String name = stdin.readLine();

I know these examples are showing different methods within these classes, but thought this might serve well for the discussion.

I'm really not sure which site is the best to ask this on.

© Programmers or respective owner

Related posts about java