Google News
logo
Java - Dynamic Input
Dynamic input
The input given to the java application at the time of execution(runtime) is called Dynamic input.
In java technology we can give the dynamic input in two ways.
1) By using BufferedReader class present in the java.io package(1.2 version)
2) By using Scanner class present in the java.util package(5.0 version)

BufferedReader program
import java.io.*; 
class Test 
{ 
public static void main(String[] args) throws Exception 
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("enter you name");
String firstText=br.readLine(); 
System.out.println("enter surname");
int secondText=br.read(); 
System.out.println("your name is "+firstText);
System.out.println("your surname "+secondText);
} 
}
Output :
output:venkat,,ch venkat,,ch
BufferedReader read integer
import java.io.*; 
class Test 
{ 
public static void main(String[] args) throws Exception 
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter a value");
int a=Integer.parseInt(br.readLine()); 
System.out.println("enter b value");
int b=Integer.parseInt(br.readLine()); 
System.out.println("addition is:"+(a+b));
} 
}
Output :
output:enter a value 20,,enter b value 30,, addition 50
Scanner
class eve{
public static void main(String ags[]){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.print(a+b)l;
}
}
Output :
output:20,,30,,50