• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Smallest and Largest Integer - Someone Rescue Me!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a problem with some code I am running for a class. I can get it to run, however, it is not returning the smallest and largest integer entered by the user. The program is running great on everything but this. I will enter the code below and see if anyone can help me to figure this out.


 
author
Posts: 23949
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Damon Ponder wrote:I am having a problem with some code I am running for a class. I can get it to run, however, it is not returning the smallest and largest integer entered by the user. The program is running great on everything but this. I will enter the code below and see if anyone can help me to figure this out.



The way you have your program coded, it will always return 100 for the smallest integer, and -100 for the largest integer. This would be true regardless of what was entered by the user... perhaps, it would be good to actually write a working Min() and Max() methods?

Henry
 
Saloon Keeper
Posts: 10646
83
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you post code or any other pre-formatted text (e.g. error message) you MUST always enclose them in "Code" tags. Paste the code into the post and then highlight it with your mouse. Then click on the "Code" button above the edit window. Then click on the "Preview" button below the edit window to see if your code has been formatted correctly. Formatted code should not include any other tags such as: bold, italic, underline, color, etc..

I'll fix it for you this time.

And welcome to the Ranch.
 
Marshal
Posts: 79039
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don't double‑space code; it isn't easier to read. I won't add to what Henry has said.
 
Carey Brown
Saloon Keeper
Posts: 10646
83
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is a mess.
  • You have comments that don't match the code: "subtract numbers" is actually a "product", and "sum" is also a "product".
  • You have a variable name "sum3" when it is not a "sum" but is a "product".
  • Your print statement starts with "Sum 3 is ...", it is not a sum. You could just leave this off the print and have "Product: ...".

  • If you use appropriate variable names and prints then the comments shouldn't even be necessary. Note that I only picked on product but your code is riddled with these issues.
    Also, you have variables Max and Min as well as methods Max and Min. Are you even using all of these? And variable names and method names must start with a lower case letter.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic