scan a string using scanner class in java

Java
    import java.util.*;
    public class ScannerExample {
    public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    System.out.print("Enter your name: ");
    String name = in.nextLine();
    System.out.println("Name is: " + name);
    in.close();import java.util.Scanner;//Import Scanner in java
import java.util.Scanner;

class classname{
  public methodname(){
    //Scanner declaration
    Scanner s_name = new Scanner(System.in);
    //Use Scanner to take input
    int val = s_name.nextInt();
  }
}
Source

Also in Java: