|
Post by Majin_Blues on Oct 27, 2001 11:36:18 GMT -5
AAACK!!! This class it driving me crazy!!! How do you stop the program from printing the same number more than once? i could do it for two digits, but once it hits 3 digit numbers, all bets are off... (i used some boolean flags, but they fall apart for 3 digit numbers or more) any ideas?
|
|
|
Post by Sky on Oct 27, 2001 19:38:00 GMT -5
well...my way of doing it is to convert the integers to string and u indexOf to solve problem...and it doesn't cuz me any problem so far...can i do it this way anyway?
and btw, for programs that is going to have any sort of input from the user...should we account for all the possible invalid input that may result in an error when running...cuz it's a lot of work doing that afterall...
|
|
|
Post by TheRock on Oct 27, 2001 20:13:52 GMT -5
how did u convert an int to String?
|
|
|
Post by Sky on Oct 27, 2001 20:21:08 GMT -5
Just look in the API booklet for Class Integer ... there is a method call static String toString...it wil tell u everything about it.... but the problem is I am not sure if this is the correct wait of doing it...I originally was thinking of using math calculation but I can't do it so... Maybe I'll ask my prof next week
|
|
|
Post by Majin_Blues on Oct 27, 2001 21:33:03 GMT -5
i (accidentally) ended up converting them all to strings...
but you do have to account for all those possible times it could screw up... so watch out for nulls or anything like that
|
|
|
Post by Sky on Oct 28, 2001 0:16:31 GMT -5
One more question...for #3 and #4 is static method means a private method within the main class...something like: public class CapitalOne { private static void extractCapitals (String s) { .... } public static void main (String [] args) throws IOException { .... } all in a single file...is it what they mean by static method?
|
|
|
Post by Sky on Oct 28, 2001 0:23:33 GMT -5
Oh well...forget about the IndexOf....just find out u can't use that ... there are some stupid small prints on the handout... ahhh...screw it well...just use charAt instead
|
|
|
Post by pandachan on Oct 28, 2001 7:21:46 GMT -5
I don't get how Number3Print works. Does it mean that:
if there is "3" in first parameter or second, print the number first parameter and second parameter? so that if first parameter is 12345 and second parameter is 67 then it prints 1234567? similarly if first = 1245 and second = 56 then it doesn't print anything?
Someone please explain how this method works!!
|
|
|
Post by Majin_Blues on Oct 28, 2001 10:46:06 GMT -5
One more question...for #3 and #4 is static method means a private method within the main class...something like: public class CapitalOne { private static void extractCapitals (String s) { .... } public static void main (String [] args) throws IOException { .... } all in a single file...is it what they mean by static method? it's something like that, but i don't suggest you use private, (i don't think you'll be able to use it outside of the class if you put it as private)
|
|
|
Post by Majin_Blues on Oct 28, 2001 11:04:42 GMT -5
I don't get how Number3Print works. ok what you're given is a parameter, say (1, 100) now, starting from the first parameter (1), your program will go through every integer between your parameters (1 - 100) and check the numbers so that if any of the digits contains the number "3", it will print it. got it?
|
|
|
Post by gundamf91 on Oct 28, 2001 12:31:04 GMT -5
it's something like that, but i don't suggest you use private, (i don't think you'll be able to use it outside of the class if you put it as private) maybe i'm too late but base on assignment 6 anncouncements, "in each of these questions (2-4) you have been asked to write a calss with a single (static) method, BUT NO MAIN METHOD. To test this class you have to write your own main class blah blah blah and so on..." i think the questions are getting more complicated and hard to understand. hope that solves your problem sky gundamf91
|
|
|
Post by Sylph on Oct 31, 2001 19:48:20 GMT -5
oh, thanks, Blues! i was doing something totally different. gundamf91, thanx too. i wasn't paying 2 much attn. ;D
|
|
Planet
Junior Member
Posts: 11
|
Post by Planet on Oct 31, 2001 20:22:36 GMT -5
This class is accually really easy. Create a static method that takes two parameters, a start number and an end number. Then print all the numbers in between them that contains the digit 3 130 143 133 345
all contain three's, so they are valid.
|
|
|
Post by Sylph on Oct 31, 2001 22:07:41 GMT -5
AAACK!!! This class it driving me crazy!!! How do you stop the program from printing the same number more than once? i could do it for two digits, but once it hits 3 digit numbers, all bets are off... (i used some boolean flags, but they fall apart for 3 digit numbers or more) any ideas? did u figure it out yet? set the boolean flag to false, and every time a 3 appears, set it to true... else, do nothing. but r u sure we have to account for nulls?! i thought u only consider it when the question discusses it, like in that damn WeatherSensor thing in a5.
|
|
|
Post by Majin_Blues on Nov 1, 2001 19:50:16 GMT -5
i got it a while back... thanks for asking! can't remember what i did though...
you don't have to account for nulls for this one...
but for those java files that require string input, i.e. not integers or stuff like that, those you have to account for nulls... or blank lines... or whatever... (except the file name programs too)
|
|