Read String from console using Scanner - Java File Path IO

Java examples for File Path IO:Scanner

Description

Read String from console using Scanner

Demo Code

import java.util.Scanner;

public class StringInputOutput {

    public static void main(String cLA[]) {

        Scanner myInput = new Scanner(System.in);

        String stringOne, stringTwo;

        System.out.println("Enter string with space");
        stringOne = myInput.nextLine();/*from  w  w  w  . j  a v a2s. c  o m*/
        System.out.printf("%s\n", stringOne);

        System.out.println("Enter string without space");
        stringTwo = myInput.next();
        System.out.println(stringTwo);
    }
}

Related Tutorials