pTutorial

New way to learn Programming

Java String Input Scanner Example

This is user define Java program to get string input from the user. We use Scanner class and Scanner class method named nextLine() to perform this task. The Scanner class is available in java.util package at rt.jar.

Java String Input Example

package pTutorial;

import java.util.Scanner;

public class InputFromUser {
    
    public static void main(String[] args) {
  
        String str;
        
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter a string"); 
        
        str=input.nextLine();
        
        System.out.println("Entered String is : ");
        
        System.out.println(str);
}
    
}

Output

Enter a string
java string example
Entered String is : 
java string example

See Also


QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER