Input from the terminal in Java

terminal

Run from terminal

Let’s say I have this class

public class Main {
public static void main(String[] args) {
System.out.println("hello, world!");
}
}

Run from the terminal with arguments

public class Main {
public static void main(String[] args) {
String name = args[0];
System.out.println("hello, " + name);
}
}
terminal
public class Main {
public static void main(String[] args) {
System.out.println("1. " + args[0]);
System.out.println("2. " + args[1]);
System.out.println("3. " + args[2]);
System.out.println("4. " + args[3]);
}
}
terminal
terminal

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store