wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes newbie question...helppp plzz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie question...helppp plzz" Watch "newbie question...helppp plzz" New topic
Author

newbie question...helppp plzz

teena abraham
Greenhorn

Joined: Dec 30, 2002
Posts: 6
im in the process of learning java. trying to write a small program. i wrote the methods. now i dont know how to invoke the methods in my main
here is the code

CAN ANYONE HELP ME.....THANKS IN ADVANCE
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ December 31, 2002: Message edited by: Dirk Schreckmann ]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

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.
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
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"
teena abraham
Greenhorn

Joined: Dec 30, 2002
Posts: 6
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 ]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

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.
teena abraham
Greenhorn

Joined: Dec 30, 2002
Posts: 6
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 ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10

[ 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
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
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.

No infinite loop here.
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28

--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
-----------------------------
[ edited to add line breaks to code -ds ]
[ January 05, 2003: Message edited by: Dirk Schreckmann ]
Divya Venkatesh
Greenhorn

Joined: Nov 05, 2002
Posts: 28
Here is the working code.I have commented your mistakes in the code.I dont know if this is what you want.If u need any clarifications do ask.

Hope you've got this clear.


Divya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie question...helppp plzz