|
Post by Brutal_Chicken on Nov 3, 2001 12:38:43 GMT -5
EDIT: Nevermind, I got it... I think.
A question though: I keep getting this error message when I use a "while" loop. The error is "Type Expected" and it's pointing to the while. Any ideas?
|
|
|
Post by Majin_Blues on Nov 3, 2001 17:49:29 GMT -5
did you define what type of variable you're using in your while statement? that is, like:
int check; while (int == 0)
|
|
|
Post by Brutal_Chicken on Nov 3, 2001 19:09:41 GMT -5
Yeah I have the conditional statement there and bracketed. Guess I'll have to figure it out in the CDF.
|
|
|
Post by Majin_Blues on Nov 3, 2001 20:01:41 GMT -5
no... i mean the thing you're using to check in your while condition... is that thing initialized/defined?
that is if you had
while blah == null
then is your "blah" variable defined?
|
|
|
Post by Newtype on Nov 4, 2001 2:26:39 GMT -5
Ok...I followed the hint that I should convert the integer into a String before checking whether the String has a 3 or not. But in order to do that, wouldn't I need to know the "variable" name of the integer?
In the API, it says: static String toString(int i) where i is the representation of the integer, and I'm stuck on what to fit for i. I don't think they will give us the variable name for the integer anyhow...
|
|
|
Post by Majin_Blues on Nov 4, 2001 12:43:16 GMT -5
if you're converting the integer to a string, you'll need 2 temporary place holders: one to check what number/integer you're checking and one to check what digit you're checking...
(you get to set what i is from your loop)
|
|
|
Post by Sky on Nov 4, 2001 12:44:53 GMT -5
i is the integer that u are going to check to see if it has number '3' in it...and since this number is different everytime during a loop u should use something like:
int count = a while (count <= b) { num = Integer.toString(count); ... } where i have the two parameters as a and b...a is the beginning and b is the end remember this is just part of the code
|
|
|
Post by Newtype on Nov 4, 2001 13:15:09 GMT -5
Hmm, ok maybe I am not understand the handouts correctly. I'm just confused. Is the program suppose to do something like:
For example, given the parameter (2,8)
1) the program will check every integers from 2 to 8 (meaning 2, 3, 4, 5, 6, 7, 8), and check if any of these digits are "3", it will print 2 3 4 5 6 7 8.
2) the autotester will have predefined integers, eg.1234567890, and the program will check this integer from the position "2" to position "8" to see if there is any 3s within this range (2-8, so now we're looking at 3456789). If it does, it will print 1234567890.
|
|
|
Post by Majin_Blues on Nov 4, 2001 13:20:57 GMT -5
it won't print out the entire interval...
it'll only print the integers that contain the number 3 inside them:
(2,8) => 3
(and only 3)
|
|
|
Post by Newtype on Nov 4, 2001 13:52:40 GMT -5
Ohhh ok. So does that mean if the parameters are (2,50), it is going to print: 3, 13, 23, 33, 43 ?
|
|
|
Post by Majin_Blues on Nov 4, 2001 14:40:57 GMT -5
careful!
it'll print out 3, 13, 23, 30-39, 43
(not just the last one but any digit)
make sure 33 isn't printed out twice (or if you test it to 400, make sure 333 isn't printed out three times, or the 330's twice, and so on)
|
|
|
Post by Brutal_Chicken on Nov 4, 2001 16:18:07 GMT -5
Oh crud. I forgot about 31-39! Converting an int to a string is the only way and not my pathetic ten incrementer.
Oh yes, the variable in the conditional statement was initialised. Weird.
|
|
Kamui
Junior Member
Posts: 6
|
Post by Kamui on Nov 4, 2001 17:06:41 GMT -5
Hey everyone ;D, can someone plz tell me what this means: Error : Incompatible type for char. Can't convert char to java.lang.String.Number3Print.java line 20 I was trying to compare a character of the string to see if it matched w/ "3". Am I on the right track or totally wrong?
|
|
|
Post by Sky on Nov 4, 2001 17:18:43 GMT -5
That mean u can't compare a char with a string... my way to get around this is create a string "3" and use charAt on it: String three = "3"; then u can compare them by: s.charAt(count) == three.charAt(0); but i don't know if the TA will take off any marks for style
|
|
|
Post by Majin_Blues on Nov 4, 2001 19:07:26 GMT -5
Error : Incompatible type for char. Can't convert char to java.lang.String.Number3Print.java line 20 I was trying to compare a character of the string to see if it matched w/ "3". Am I on the right track or totally wrong? you assigned a char, but you can't compare it to a string... you're on the right track though to make sure a char is checked as a string and not its numerical value, make sure it matches with '3' instead of "3" - note the single quotation marks - it really makes a big difference
|
|