I know only 6 methods to read input from keyboard/user.......
1. Command line argument
2. System properties
3. java.util.Scannner(from jdk1.5)
4. using console (from jdk1.6)
5. BufferedReader
6. using AWT / SWING
input.java
import java.io.BufferedReader;
import java.io.Console;
import java.InputStreamReader;
import java.util.Scanner;
public class input{
public static void main(String as[])throws Exception{
//command line argument
String name1=as[0];
//System property
String name2=Sysytem.getProperty("myname");
//scanner class
Scanner sc=new Scanner(System.in);
String name3=sc.next();
Console cons=System.console();
String name4=cons.readLine();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter name");
String name5=br.readLine();
System.out.println(name1+" "+name2+" "+name3+" "+name4+" "+name5);
}//main
}//class
//>javac input.java
//>java -Dmyname=pd input pandurang
1. Command line argument
2. System properties
3. java.util.Scannner(from jdk1.5)
4. using console (from jdk1.6)
5. BufferedReader
6. using AWT / SWING
input.java
import java.io.BufferedReader;
import java.io.Console;
import java.InputStreamReader;
import java.util.Scanner;
public class input{
public static void main(String as[])throws Exception{
//command line argument
String name1=as[0];
//System property
String name2=Sysytem.getProperty("myname");
//scanner class
Scanner sc=new Scanner(System.in);
String name3=sc.next();
Console cons=System.console();
String name4=cons.readLine();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter name");
String name5=br.readLine();
System.out.println(name1+" "+name2+" "+name3+" "+name4+" "+name5);
}//main
}//class
//>javac input.java
//>java -Dmyname=pd input pandurang
No comments:
Post a Comment