Ways to take Input from console and produce some output in Java

Here are some ways through which you can take input from the console in Java.

import java.io.*;
import java.util.Scanner;class A1{
public static void main(String[] args) throws IOException{
DataInputStream dis=new DataInputStream(System.in);
System.out.println(“Enter a number”);
int num=Integer.parseInt(dis.readLine());
System.out.println(num);
}
}

class A2{
public static void main(String[] args){
System.out.println(args[0]);
}
}

class A3{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println(“Enter a string”);
String n=in.next();
System.out.println(n);
}
}

class A4{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter a string”);
String n=br.readLine();
System.out.println(n);
}
}

class A5{
public static void main(String[] args){
Console c=System.console();
System.out.println(“Enter a username”);
String s=c.readLine();//overloaded
System.out.println(“Enter a password”);
char[] ch=c.readPassword();//overloaded
System.out.println(“Username: “+s+” Password: “+new String(ch));
}
}