It's not a secret anymore!*
The moose likes Beginning Java and the fly likes execution program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "execution program" Watch "execution program" New topic
Author

execution program

charushila ingale
Greenhorn

Joined: Mar 02, 2009
Posts: 6
hello friends,
i am new in java i have problem in the program

this is my program but it gives me the answer like this but i want addition numbers which we are entering


E:\charu\java-program>java MathTest
Enter value of x: 2
Enter value of y : 1
x: 2y :1
Addition = 11Subtraction = 3

any one tell me why it is not giving the user input
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Please UseCodeTags. You can use the edit button to add them. And don't forget to keep the indentation within the code tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Are you sure that your code compiles? It shouldn't, because you are creating a new Math object with: Math m = new Math(); but your class Math does not have a constructor that takes no arguments.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
charushila ingale
Greenhorn

Joined: Mar 02, 2009
Posts: 6
Jesper Young wrote:Are you sure that your code compiles? It shouldn't, because you are creating a new Math object with: Math m = new Math(); but your class Math does not have a constructor that takes no arguments.

i am giving two arguments
7and 4
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

No, you aren't. Look in the source code that you posted above. You have this line in the main() method:

Math m = new Math();

If you try to compile that, you will get a compiler error, because your class Math does not have a constructor that takes no arguments. It only has a constructor that takes two int arguments:

I don't see two arguments 7 and 4 being passed in your code above.

Maybe your actual code is different from what you posted above. Are you really doing this?

Math m = new Math(7, 4);

If yes, then why are you surprised at the output? Because 7 + 4 = 11 and 7 - 4 = 3.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Charushila,
Like Rob requested you before, in future, while posting code, please UseCodeTags
I have edited your original post to incorporate them. As you can see it makes the code much more readable and easier to understand.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
charushila ingale
Greenhorn

Joined: Mar 02, 2009
Posts: 6
Jesper Young wrote:No, you aren't. Look in the source code that you posted above. You have this line in the main() method:

Math m = new Math();

If you try to compile that, you will get a compiler error, because your class Math does not have a constructor that takes no arguments. It only has a constructor that takes two int arguments:

I don't see two arguments 7 and 4 being passed in your code above.

Maybe your actual code is different from what you posted above. Are you really doing this?

Math m = new Math(7, 4);

If yes, then why are you surprised at the output? Because 7 + 4 = 11 and 7 - 4 = 3.


i am very sorry
my code is different from this
you are true and i want addition of those number which are given by user mean i want addition of number 2 and 3

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

charushila ingale wrote:my code is different from this

Please PostRealCode. If you don't post the real code then we can't help you out.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

charushila ingale wrote:you are true and i want addition of those number which are given by user mean i want addition of number 2 and 3

I guess you want the addition and subtraction to be done with the numbers that the user types in.

What you'll have to do is first input the numbers, and then create the Math object, passing it the numbers you've just gotten from the user (x and y). You'll have to move line 7 of your source code down to around line 19.

Take your time, carefully look at the source code line by line, and make sure that you understand what each line of code is doing exactly - follow the flow of the program, so that you understand what the whole program is doing exactly.
ahamed irshad
Ranch Hand

Joined: Feb 26, 2010
Posts: 31

...


You can do anything, but not everything
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Ahamed,

I am sure you meant well, but please do not post ready made solutions. The best way to learn is by making mistakes and identifying the mistakes.
I hope you appreciate this and take it in the right spirit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execution program
 
Similar Threads
GCD/LCM problems
Scanner
Confused about Dan's exam...
Inner class question from Dan's exam
Anonymous inner class