Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



visual-example.jpg
[Thumbnail for visual-example.jpg]
program screenshot with needed element
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 76479
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bras cause cancer. And tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic