• Post Reply Bookmark Topic Watch Topic
  • New Topic

Largest Of Input Numbers.  RSS feed

 
Paul Brandon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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!


 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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?
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!