How to accept user input in Java ⌨️【8 minutes】
Bro Code Bro Code
2.21M subscribers
205,485 views
8.9K

 Published On Oct 13, 2020

Java user input scanner

#Java #input #scanner

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("What is your name? ");
String name = scanner.nextLine();

System.out.println("How old are you? ");
int age = scanner.nextInt();
scanner.nextLine();

System.out.println("What is your favorite food?");
String food = scanner.nextLine();

System.out.println("Hello "+name);
System.out.println("You are "+age+" years old");
System.out.println("You like "+food);

}
}

show more

Share/Embed