aspose file tools*
The moose likes Beginning Java and the fly likes Java method to output difference between two numbers as a comparison showing the highest number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java method to output difference between two numbers as a comparison showing the highest number" Watch "Java method to output difference between two numbers as a comparison showing the highest number" New topic
Author

Java method to output difference between two numbers as a comparison showing the highest number

William Kovacs
Greenhorn

Joined: Oct 20, 2012
Posts: 1
I have an issue trying to create a method successfully to get the difference of two integers (sales) and displaying them. I have a working program and it's all good but I need to find a way to add this to what I have. It's not the end if I can't get it but I have a personal interest in it now. Should I post code too? It's two classes....It is a homework question but I want to know for myself. I've been doing this over 10 hours now and have a pretty decent program going but I need this element to finalize my brain and get peace...


________________________________________________________________________________________________________________end of main class






[Thumbnail for visual example.jpg]

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

William Kovacs wrote:I have an issue trying to create a method successfully to get the difference of two integers (sales) and displaying them.

Right.

1. Please UseCodeTags (←click). And please read the page thoroughly, because some of your lines are far too long. You can use the Edit button to add the tags and break up those enormous lines.

2. I'm not quite sure what your problem is. Given two integers, i1 and i2, the simplest way to display their difference is:
System.out.println(i1 - i2);
however I suspect there's more to your problem than just that, so please explain it fully.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
It is not only the lines that are too long (if you look, I have added code tags and broken the lines, so you can see how it is done, but you would have done it better yourself), but the whole thing is too long. You should write 5 lines, compile and run them, and see what happens. Then write another 5 lines, etc. That way you find out much sooner when something goes wrong. As it is, there is too much code for us to read.
One thing I noticed, however, which I didn’t like, is that you are combining different ways to format output. Use printf or DecimalFormat, but not both. I would suggest you get rid of DecimalFormat altogether. Get rid of the \n character too; use the %n tag instead and printf throughout.

And welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java method to output difference between two numbers as a comparison showing the highest number