+ 3
What is the use of scanner in java?? Could any one please explain.. And give a small example too..
4 ответов
+ 6
The Scanner class is mainly used to get the user input, and it belongs to the java.util package. In order to use the Scanner class, you can create an object of the class and use any of the Scanner class methods.
see this example---
import java.util.Scanner;// Import the Scanner class
public class Example {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);// Create a Scanner object
System.out.println("Enter username");
String name = s.nextLine();// Read user input
System.out.println("name is: " + name);// Output user input
}
}
for better explanation you can visit here
---------------. ---------. -------- -----------------
https://www.google.com/amp/s/www.geeksforgeeks.org/scanner-class-in-java/amp/
+ 7
The Java Scanner class is used to read user input. Scanner is built into the java.util package, so no external libraries are needed to use it. While Scanner is the most common class used to retrieve input, Java’s BufferedReader, InputStreamReader, DataInputStream, and Console classes can also be used.
Example:-
import java.util.Scanner; // import java.util.*;( "*" is also used instead of scanner)
public class yourName{
public static void main(String [] args) {
Scanner input = new Scanner (System.in);
String name = input.nextLine() ;
System.out.println(name) ;
}
}
+ 4
Pàví(◠‿・)—☆(◠‿・)—☆ welcome
+ 2
Tqq