Forum : query on control flow section
Brief description  about Online courses   join in Online courses
View Sarjana  Panda 's Profile

query on control flow section

how to take an input dynamicaly
Asked by Sarjana Panda | Feb 17, 2011 |  Reply now
Replies (3)
View sr k 's Profile
keep posting :)
Feb 17, 2011
View sarjana panda 's Profile
thank you
Feb 17, 2011
View sr k 's Profile
Hi Sarjana Panda,


u can take input in java at runtime using couple of ways the best way i feel is illustrated below


import java.io.*;//note that this import statement is must because we are using a class of that package
public class runtime
{
public static void main(String[] args)
{

try
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter some string");
String x = br.readLine();//this line reads the entered string at runtime and stores it in string variable x
System.out.println("the string u entered is "+x);
}
catch(Exception e)
{
System.out.println("some error occurred);
}
}
}//end of class runtime

Output:
enter some string
Sarjana Panda
the string u entered is Sarjana Panda
Feb 17, 2011