I have written a "dummy" code, because i need to understand a concept, then apply it to other programs. So, help me solve this dummy code, it is not homework. what i need is: 1. how to use a boolean properly. 2. use the object num in the tester // i dont know why it doesnt work. 3. make a do-while in the tester, so it will ask "enter a number" until the user enters a number greater than 10. if the user enters less than 10 i want the program to loop the question until done right.
i figured. however, i've tried many different options like while(dido.getNum) // it doesnt read dido. while( num ) // anything with num doesnt work. i know im close, but what am i missing to make this dummy code?? i need this concept so i can move on a bigger much bigger project.
What Henry's saying is important. Unlike c, java's zero is not equal to false. A Java while loop expects a boolean condition.
Thus, #1 is legal
1. while (dido.getNum != 0)
but #2 is not
2. while (dido.getNum)
The difference is that #1 is comparing a boolean condition is dido.getNum equal to zero, while #2 is trying to evaluate an number dido.getNum as a boolean: that just doesn't work in Java.
hth, M [ April 01, 2006: Message edited by: Max Habibi ]
i dont really understand what you are saying. however, this code isnt working, i get an error: " cannot find symbol symbol : variable dido location: class Ktester while(dido.getNum != 0);" if its not asking too much, could you please fix the code so it works, then explain me what you did. thanks for the support.
Anything declared inside a set of brackets is only available inside those brackets. Declare dido above the do-while loop. Also read about scope, it is an extremely important concept and you will have nothing but frusterations until you understand it.
People already told you want you need, a loop condition requires a boolean value, not an integer. [ April 01, 2006: Message edited by: Rusty Shackleford ]
Ok, thanks alot, i know now how to make the "dido" work so simple yet so complicated if you dont know. now the problem i have is that the boolean is not doing what it is supposed to.
i've got the problem to loop "enter number" if i enter a number less than 10 or greater than 10. however when i enter 10, the loop stops.
I guess the part that i dont understand is that my boolean method says that it if its greater than 10 is true and if its less then is false - in my mind, i understand this as if you enter greater than 10 well you end the loop correctly, but if you enter less than 10 the question "enter number" will be asked again. is that how it works?? and how do i make it work so if the user enters any number below 10 it asks again, and if it enters a number greater than 10 it end the loop. phew, i hope you guys can help me. thanks.
Incidentally, as far as naming conventions go, getXXX() usually implies a non-boolean return value. For booleans the convention usually isXXX() or hasXXX(). However these are just conventions and they can be (and frequently are) broken all the time. I only mention this because a more conventionally desciptive namr for your method might be hasGoodData()
Incidentally, as far as naming conventions go, getXXX() usually implies a non-boolean return value. For booleans the convention usually isXXX() or hasXXX(). However these are just conventions and they can be (and frequently are) broken all the time. I only mention this because a more conventionally desciptive namr for your method might be hasGoodData()
LOL u beat me to it, thanks anyways, that was the solution, man it was right in front of me the whole time =D
Post by:autobot
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards