Read string via Scanner - Java File Path IO

Java examples for File Path IO:Scanner

Description

Read string via Scanner

Demo Code


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in); // use the Scanner class to read from stdin
        System.out.println("What's your input string?");
        String inputString = scan.nextLine(); // read a line of input and save it to a variable
        scan.close(); // close the scanner

        // Your first line of output goes here
        System.out.println("Hello, World.");

        // Write the second line of output
        System.out.println(inputString);
    }//from  w  w  w.jav a 2s .  com
}

Related Tutorials