• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

execution program

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22742
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22742
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 31
Opera C++ Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic