• 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

Largest Of Input Numbers.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to Java.
I think the problem in this is that the variable max is initialised as 0. Afterwards it remains in the while loop only, so the output is always 0.
I dont know how to bring the last max value out of loop and print it.
Any help would be appreciated!


 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look closely at Line 29 and Line 30, and tell me if you can answer this question: When is "a >= input" ever not true?
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, take a look at how your assignment statements in lines 31 and 34 are written. In Java (and most programming languages that I know), assignment statements are of the form: Set variable equal to value. The variable named on the left side of the equals sign gets its value replaced with the expression on the right side of the equals sign. In other words, the only place in your program where the variablemax is assigned a value is on line 19 (That's the only place where max is on the left side of the equals sign).
 
Paul Brandon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stevens Miller wrote:Look closely at Line 29 and Line 30, and tell me if you can answer this question: When is "a >= input" ever not true?



There should be no inequality.

Joel McNary wrote:Also, take a look at how your assignment statements in lines 31 and 34 are written. In Java (and most programming languages that I know), assignment statements are of the form: Set variable equal to value. The variable named on the left side of the equals sign gets its value replaced with the expression on the right side of the equals sign. In other words, the only place in your program where the variablemax is assigned a value is on line 19 (That's the only place where max is on the left side of the equals sign).



Thank you.

It works now.
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joel McNary wrote:Also, take a look at how your assignment statements in lines 31 and 34 are written. In Java (and most programming languages that I know), assignment statements are of the form: Set variable equal to value. The variable named on the left side of the equals sign gets its value replaced with the expression on the right side of the equals sign. In other words, the only place in your program where the variablemax is assigned a value is on line 19 (That's the only place where max is on the left side of the equals sign).



Only thing I liked about APL was its use of "←" instead of "=" for assignment.
 
reply
    Bookmark Topic Watch Topic
  • New Topic