Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get input via command line in Java? [closed]

Tags:

java

I currently have this code that needs user input to pseudo-ify some words to send out and commit obfuscation on the integer later. I just need to get the user input. Anyone have a good source of api to get this from? I think I should be looking for System. commands.

Thanks in advance :)

like image 823
user2262111 Avatar asked Dec 03 '22 23:12

user2262111


1 Answers

The Scanner class was implemented in Java 5.0 to make getting input easier:

Scanner input = new Scanner(System.in) the System.in will allow for console input.

Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
/* will wait for input then assign it to the variable,
 * in this case it will wait for an int.
 */
System.out.println(i); // will print the variable

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

like image 65
Joban Dhillon Avatar answered Dec 16 '22 15:12

Joban Dhillon