How to take input from user in java?

DWQA QuestionsCategory: QuestionsHow to take input from user in java?
Editor Staff asked 3 weeks ago

How to take input from user in java?

1 Answers
Editor Staff answered 3 weeks ago

“import java.util.Scanner;
Scanner console = new Scanner(System.in);
int num = console.nextInt();
console.nextLine() // to take in the enter after the nextInt()
String str = console.nextLine();”