0

I would like to know what are the differences between reading data in the next programs

The first one read data using a Scanner and the second one uses io

I know that we could also use JOptionPane but I would like to know the difference between using one or other option or if there are some of them which can only be used in specific cases.

You would really help me if you could answer, thanks any way for readind this, I appreciate it. C:

package test;
import java.util.Scanner;

class Test{

    public static void main(String [] args){

         Scanner sc = new Scanner(System.in);
         String name;

         System.out.println("Ptss ...Tell me your name please.");
         name = sc.nextLine();

         System.out.println(name + " It's a pleasure to meet you");

    }
}



    package test;
    import java.util.io.*;

    class Test{

        public static void main(String [] args) throws IOException{

             BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
             String name;

             System.out.println("Ptss ...Tell me your name please.");
             name = read.readLine();
             System.out.println(name + " It's a pleasure to meet you");
        }
    }
Heriberto Juarez
  • 270
  • 2
  • 18
  • You can use either for this; you just can't get an `int` (and other types) directly from the `BufferedReader` like you can with a `Scanner`. – Andy Turner Mar 13 '17 at 01:06
  • In case you are new to Java import java.util.Scanner imports java.util.Scanner class whereas import java.io.* imports all the classes in java.io package. – opensam Mar 13 '17 at 01:09
  • Thanks to everyone who has answered. That helps a lot Andy, thanks. Eclipse: I have checked the other question and though its not exactly what i was looking for it is very helpful, thank you so much. opensam: I didn't know that, It makes me happy that you helped me learn something new, thank you. – Heriberto Juarez Mar 13 '17 at 01:10

0 Answers0