0
votes

Pourquoi (System.in) est passé en paramètre lors de l'instanciation d'un nouvel objet de classe Scanner?

Sans System.in dans l'instanciation de la classe du scanner, je ne peux attribuer aucune valeur à partir de mon clavier. Que se passe-t-il exactement. Quelqu'un peut-il élaborer s'il vous plaît.


1 commentaires

Étant donné que la classe scanner peut également lire à partir d'autres sources (comme des fichiers), vous devez savoir d'où exactement.


3 Réponses :




1
votes

Depuis Javadoc: Classe Scanner

| Constructor                                             | Description                                                                            |
|---------------------------------------------------------|----------------------------------------------------------------------------------------|
| Scanner​(File source)                                    | Constructs a new Scanner that produces values scanned from the specified file.         |
| Scanner​(File source, String charsetName)                | Constructs a new Scanner that produces values scanned from the specified file.         |
| Scanner​(File source, Charset charset)                   | Constructs a new Scanner that produces values scanned from the specified file.         |
| Scanner​(InputStream source)                             | Constructs a new Scanner that produces values scanned from the specified input stream. |
| Scanner​(InputStream source, String charsetName)         | Constructs a new Scanner that produces values scanned from the specified input stream. |
| Scanner​(InputStream source, Charset charset)            | Constructs a new Scanner that produces values scanned from the specified input stream. |
| Scanner​(Readable source)                                | Constructs a new Scanner that produces values scanned from the specified source.       |
| Scanner​(String source)                                  | Constructs a new Scanner that produces values scanned from the specified string.       |
| Scanner​(ReadableByteChannel source)                     | Constructs a new Scanner that produces values scanned from the specified channel.      |
| Scanner​(ReadableByteChannel source, String charsetName) | Constructs a new Scanner that produces values scanned from the specified channel.      |
| Scanner​(Path source)                                    | Constructs a new Scanner that produces values scanned from the specified file.         |
| Scanner​(Path source, String charsetName)                | Constructs a new Scanner that produces values scanned from the specified file.         |
| Scanner​(Path source, Charset charset)                   | Constructs a new Scanner that produces values scanned from the specified file.         |

Pour spécifier le type de Scanner que vous voulez, vous devez passer un paramètre. System.in indique à la classe Scanner que depuis la source InputStream


0 commentaires