Tag » Scanner

Using Scanner to take input from Console in Java

This small program to show how to take input from console (can be single or multiple lines)

public static void main(String[] args) throws Exception {
    Scanner console = new Scanner(System.in);
    Scanner lineTokenizer;

    int lineCount = 0;

    // this is to handle all 'lines'
    while (console.hasNextLine()) {
        String lineContent = console.nextLine();
        System.out.println(String.format("Line %d is %s", ++lineCount, lineContent));

        if (lineContent == null || lineContent.isEmpty()) {
            // this is to exit the program if there is no input anymore
        lineTokenizer = new Scanner(lineContent);

        int itemCount = 0;

        // this is to handle a 'line'
        while (lineTokenizer.hasNext()) {
            if (lineTokenizer.hasNext()) {
                long number = lineTokenizer.nextLong(); // consume the valid token

                System.out.println(String.format("Line %d - Number #%d is %d", lineCount, ++itemCount, number));
        lineTokenizer.close(); // discard this line

    console.close(); // discard lines.
32 kata lagi

The phone to beat in 2016

(Source: www.businesstimes.com.sg)

THESE days, it is hard for any tech company to keep to an annual product launch cycle, without being called out for releasing what is effectively a slight upgrade over the last model. 920 kata lagi

Money Matters

Police Scanners

I am currently in the midst of UGA graduate school. I was sitting in my room earlier today working on an assignment for class. It brought chills when I read a quote from one of our books. 334 kata lagi

13 things the Galaxy Note 7 can do that the iPhone can't do

(Source: www.businessinsider.sg)

Samsung’s best phone ever, the Galaxy Note 7, comes out in just a few days. 

We already have our full review here… 299 kata lagi