• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execution program

 
charushila ingale
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. You can use the edit button to add them. And don't forget to keep the indentation within the code tags.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
charushila ingale
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
charushila ingale
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
C++ Notepad Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic