Is it possible to keep looping until the user key-in "quit", without asking the same question over and over again?
The 'input' variable can only be an 'int' or a 'String', right? So, how do we use the same variable to compare 2 different things?
SCJP, SCWCD.
|Asking Good Questions|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Originally posted by Campbell Ritchie:
Somebody else had a rather similar problem back in the Spring; maybe her thread will help: here.
But it is particularly awkward trying to check whether a String is a number or "quit" in the same statement.
Originally posted by Campbell Ritchie:
Suggested enhancements, nothing to do with the input:
Alter the set of ifs to dispense with the <= tests.
I don't understand, why is it of no value? How do we test if input is in the range of 0 to 100? In maths, it is (0 < input < 100). How do we write this in programming format?Originally posted by Campbell Ritchie:
Work out why while (input3 > 0 | input3 <= 100) is of no value, and what the logicians call that sort of construction.
Originally posted by Campbell Ritchie:
[list]Find out why you ought to use || and && rather than | and &. Reduce the bank of ifs to a switch with not more than 11 cases.
Originally posted by Campbell Ritchie:
all those points have to do with the doComparison method or the old doCompare method.
Originally posted by Campbell Ritchie:
Using a switch?
Originally posted by Campbell Ritchie:
Why is (input3 > 0 | input3 <= 100) valueless? Back to the drawing board for those two. I'll look tomorrow morning and see how you have got on.
(input3 > 0 | input3 <= 100)
The case one is not displaying the grade at all.
SCJP, SCWCD.
|Asking Good Questions|
Originally posted by myself:
. . . case = "oops";
Originally posted by Amit Ghorpade:
It is never evaluated to true!!
Just take a look at the switch, you switch on input, then there are cases 1 to 5. Then in each case there is a if checking the input value.
If the input is say 50, then none of the cases match.For a input 1, case 1 has a match, but the if fails.
I dont think switch is the solution, you should consider using if-else if construct. Hope this helps
Originally posted by Campbell Ritchie:
Henry's suggestion about converting Strings to ints or vice versa looks useful; there are methods in the String class which allow you to compare Strings. Then you need to work out what you are comparing the String to.
Originally posted by Garrett Rowe:
Consider Paul's rocket mass heater. |