It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

getting values from user

getting values from user

Postby ghosh on Sat Dec 30, 2006 2:41 am

Dear friends
I have joined a course on SCJP. I had no prior knowledge about java programing.

Can any one plese tell me how to get in put from user :?: All I am trying to do it to get two values from user and print the sum, product, or the same.

Thanks
Ghosh
ghosh
 
Posts: 7
Joined: Sat Dec 30, 2006 2:24 am

Postby ngpgeeta on Sun Dec 31, 2006 8:02 am

When you run a java program from command prompt, you type c:>java name_of_file

Now along with it type 2 and 3. ie
c:>java name_of_file 2 3

This 2 will get stored in args[0] and 3 in args[1] ie in your program where you write
public static void main(String args[])
{
int x= Integer.parseInt(args[0]);
int y= Integer.parseInt(args[1]);
}

Now x =2 and y=3 and you can use it for addition etc.
ngpgeeta
 
Posts: 19
Joined: Sat Nov 18, 2006 11:30 am

Postby ghosh on Mon Jan 01, 2007 1:54 am

Hmm.. I know this. This for getting values from the user in command line. This will definitely help me but I was looking for the general method like the one we use in C++

count>> "enter two number";
int num1, num2;
cin<<num1

Ghosh
ghosh
 
Posts: 7
Joined: Sat Dec 30, 2006 2:24 am

Postby meongmania on Wed Jan 03, 2007 9:36 am

public static void main(String[]args){
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

System.out.print("input 1 : ");
int num1 = Integer.parseInt(input.readLine());
System.out.print("input 2 : ");
int num2 = Integer.parseInt(input.readLine());
System.out.println("Result : "+(num1+num2));
//etc...
}
meongmania
 
Posts: 16
Joined: Tue Dec 19, 2006 2:58 am

Postby ghosh on Thu Jan 04, 2007 5:34 am

Thanks meongmania


Ghosh
ghosh
 
Posts: 7
Joined: Sat Dec 30, 2006 2:24 am


Who is online

Users browsing this forum: No registered users and 0 guests