Results 1 to 11 of 11
- 03-03-2011, 04:33 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Suggestions for writing this algorithm
I am currently working on an assignment to write an algorithm in Java to produce and output that is of the perfect squares 1-15. (ie, 1, 4, 9, 16, 25.... 225)
What I have now is...
I think i started out okay, but I'm rather lost.Java Code:class PerfectSquares{ public static void main(Strings args[]){ int i; for(i=1;i<=15;i++){ System.out.println(i*i); } } }Last edited by Eranga; 03-03-2011 at 04:53 AM. Reason: code tags added
- 03-03-2011, 04:37 AM #2
Does your code compile?
Does it run?
Does it produce correct output?
I'm also lost as I don't know what your problem is.
- 03-03-2011, 04:48 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
It compiles fine, but when i run the .class file, it gives me an "exception in the thread "main" java.lang.NoClassDefFoundError: PerfectSquares/class"
The issue at the moment is that I can't get it to output the perfect squares of 1-15, and I'm not quite sure how to change it, so that it does.
- 03-03-2011, 04:52 AM #4
Are you running your code from the command line? If so the commands are:
Compile
javac MyProgram.java
Run
java MyProgram
Note how you leave the .class off.
- 03-03-2011, 04:52 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
How did you compile and run your class?
- 03-03-2011, 04:54 AM #6
- 03-03-2011, 05:02 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Wow... I feel like an absolute idiot right now.
Earlier it compiled fine. This time I compiled it, and it gave me the error, "classPerfectSquare2.java:2: cannot find symbol
symbol : Class strings
location: class PerfectSquares
public static void main(strings args[]){"
so i fixed the strings into string.
and it compiled and ran like a charm.
I appreciate all your help! Sorry for wasting your time.
- 03-03-2011, 05:08 AM #8
- 03-03-2011, 09:00 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
@Slin9: you should be more exact: you mention 'Strings' in your original post, you mention 'strings' in this post and you claim that your program compiles when you changed it to 'string'. You also didn't mention the compiler errors thrown at you nor the runtime errors when you tried to start your program an yet you wanted us to help you. We can't help you if you don't supply this vital information. This all may seem nitpicking to you but it isn't; we are not psychic; help us to help you; the more accurate your information is you supply the more accurate the answers will be.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-04-2011, 06:13 PM #10
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
@Jos: I realized this the further I got along in this thread. Next time I will know better, as you can tell, I'm quite new at this. I thank everyone for their patience and help. Even thought I didn't provide vital information, you guys still asked me questions, that helped me think more thoroughly about the code, which was a great help all in itself!
Thanks again!
- 03-04-2011, 07:10 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
You're welcome of course; real programmers (like me) are real nitpickers, i.e. they notice every little detail so those details better be correct otherwise your thread may go astray into lala-land with discussions about details that don't matter. In fact it's simple: supply a small, compilable snippet of code that demonstrtates the problem; also supply the compiler error message(s) (if any) and give an accurate description of how your code is misbehaving. Otherwise your threads end up like a guessing game or they're simply ignored.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
[suggestions] minesweeper
By temyong in forum New To JavaReplies: 7Last Post: 12-30-2010, 03:10 AM -
looks good looking for suggestions..
By search4survival in forum New To JavaReplies: 10Last Post: 11-30-2010, 12:59 PM -
Looking for suggestions
By tonino in forum New To JavaReplies: 5Last Post: 09-26-2010, 07:17 PM -
Book suggestions
By Lil_Aziz1 in forum Java AppletsReplies: 3Last Post: 01-04-2010, 02:38 AM -
any suggestions?
By PureAwesomeness in forum New To JavaReplies: 4Last Post: 01-19-2009, 07:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks