A: Scanner is most similar to How does BufferedReader class works?
BufferedReader is under "io" class while Scanner is under "util".
Since they have similarities, In this example, same problem will be solved as the link above.
//import the Scanner class
import java.util.Scanner;
//public class pangalanNgProject
public class Scan{
public static void main(String[] args) {
//set a Scanner name. (realmyn)
Scanner realmyn = new Scanner(System.in);
String pangalanNgUser;
System.out.println("anu pangalan mo? ");
pangalanNgUser=realmyn.nextLine();
System.out.println("kumusta ka " + pangalanNgUser+"?");
}
}
OUTPUT:
anu pangalan mo?
Juan
kumusta ka Juan?
Good Programming Practice:
Use variable names which you can easily understand for better coding.
No comments:
Post a Comment