Instead of filling in a String or another type we use the command “System.in” to obtain data from a user. This looks like this:

package P;

import java.util.Scanner;

public class C {
	
	C() {
	}
	
	void start() {
		Scanner in = new Scanner(System.in);
	}
	
	public static void main(String[] args) {
		new C().start();

	}

}
  • scanner in constructor
package P;

import java.util.Scanner;

public class C {
	
	Scanner in;
	
	C() {
		in = new Scanner(System.in);
	}
	
	void start() {
	}
	
	public static void main(String[] args) {
		new C().start();

	}

}

In these two examples, we asked the input from the user. If you want to know how to fill in the input yourself (the programmer) or ask it from a file, check the following links: