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");
}
}