You can get input from keyboard with two methods.
1nd method (System.in):
import java.io.*;
public class input {
public static void main(String args[]){
try{
System.out.print("What's your name? ");
DataInputStream in=new DataInputStream(System.in);
String name = in.readLine();
System.out.println("Your name is " + name + "!");
}catch(IOException e){}
}
}
Compile the code and run it. The program will ask you about your name. Type your name and press Enter key and program will show your name.
2nd method (arguments):
public class args {
public static void main(String args[]){
if(args.length == 0) {
System.out.println("Type your name as: java args John\n or java args \"John Doe\"");
}
else {
System.out.println("Your name is " + args[0] + "!");
}
}
}
Compile the code and run it. The program will not ask you about your name. Type your name as: java args name and press Enter key and program will show your name.