Teena, Method "main()" is a static method (since it is defined using the 'static' keyword). The other methods in your "test" class are instance methods (i.e. not static). In order to invoke an instance method, you need an instance. So, in my opinion, you have two choices: 1. make all the instance methods static methods 2. create an instance of class "test" in method "main()", example:- test aTest = new test(); Then you can do the following:- aTest.do0_9(); Hope this has helped you. Good Luck, Avi.
Kind of off the subject, but your methods also have a bug:
Since your method does not increment i (e.g. i++), i will never reach 100 so your program will print "9" repeatedly - probably not what you intended. [ December 31, 2002: Message edited by: Blake Minghelli ]
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Joined: Dec 30, 2002
Thanks Avi and Blake I made modifications according to ur sugegstions but im getting a runtime error..... :roll: here is the code
dont know where i went wrong....any help appreciated [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ December 31, 2002: Message edited by: Dirk Schreckmann ]
Teena, I copied the code you posted here, compiled it and ran it -- and I didn't get a runtime error. I am using JDK 1.4.1_01 on Windows 2000. However, you did not correct the mistakes that Blake pointed out, so when I execute the "Empty" class and supply a value greater than 9 (nine), I get an infinite loop! Perhaps you would care to post the runtime error message (and accompanying stack trace) that you are getting? Good Luck, Avi.
Joined: Dec 30, 2002
Thanks avi for spending ur valuable time in teaching me the basics of java. stupid of me wat happened is i didnt give a number and pressed enter button. actually i have changed the code wat Blake has pointed out. but i cut and pasted the pre version. but even then its going as an infinite loop
(code tags added by Marilyn) [ January 01, 2003: Message edited by: Marilyn de Queiroz ]
[ January 01, 2003: Message edited by: Marilyn de Queiroz ]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Joined: Jul 22, 2000
but even then its going as an infinite loop
I don't see an infinite loop....
Perhaps you need to define what you want your program to do.
The current program does this:
Get input from keyboard Parse it if ( x < 10 ), print all numbers from zero to (but not including) 9 else if ( x < 100 ), print all numbers from zero to (but not including) 99 else if ( x < 1000 ), print all numbers from zero to (but not including) 999.