+ 1

I dont get the scanner thing in java at all

can anyone suggest any yt videos or somerhing?

27th Jan 2018, 8:03 AM
Stanisław
Stanisław - avatar
2 Respuestas
+ 1
In Java, IO is dealt with using InputStreams and OutputStreams. Here is the documentation for Scanner. https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html Notice in the constructor section there are different things you can use when creating a scanner. You can use a File or some Readable source, but also an Inputstream. Now historically we have the standard input and output streams that interact with the console, and Java similarly has a System.in Inputstream and System.out OutputStream (this is why you use System.out.println, you are writing content to the output stream!). So this line Scanner sc = new Scanner(System.in) constructs a Scanner that reads from the standard in. You might think that Scanner is what captures user input, but it's not, System.in is. What Scanner does is turn this input stream (basically streams of raw bytes) into something easy to use. It performs some optimisations and deals with locale etc. Calling sc. nextLine () sc.next() sc.nextInt() etc are convenient ways to access the data stored from the stream. In a way, nextLine() is the counterpart to println() - reading from, or writing to different streams. That's literally all it is :) have a look through the docs to see what other things you can call on it. Hope this helps
27th Jan 2018, 8:45 AM
Dan Walker
Dan Walker - avatar
0
You can check out 'thenewboston' on youtube.
27th Jan 2018, 8:32 AM
Amit Gupta
Amit Gupta - avatar