Raine RaineAndrews

Greenhorn
+ Follow
since Jun 27, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Raine RaineAndrews

That's why it spit "can't divide by zero" at me! I'll change it to =1 and get rid of that nasty looking booleon to boot! And if I cut down the amount of calculations by restricting the while loop for divisors, I get a more elegant piece of code

I also figured out I don't need an else statement, and that Divisors++ shouldn't be part of the if statement, but part of the While loop for divisors. What a simple mistake, with such a big consequence!

Here's the finished code!



Thanks for the help, I learned a lot about Java loops on this program!
13 years ago
Thanks! Deleting the semicolon and adding a { didn't seem to help, but I followed your advice on using if and else statements. I actually got output! Unfortunately, my output was 1 with 1 divisor, which can't be right. I'm betting that I need an Else statement in there somewhere right?

I had to change the booleon regarding divisors (line 18) to not accept 0 because it was trying to divide by zero for some reason. I think by fixing the symptom and not the problem may have ruined the process however.

No piece of advice is too small, I'm just starting and I'm self teaching through doing. It gives me headaches, and it takes forever to learn how to put together simple code, but I'm a heck of a lot further than I would be reading instead of doing!

Here's the code that feeds me 1 with 1 divisor



Here is the code where I take a stab at the else statement...



Thanks again for any help. This site is really Greenhorn friendly (go figure!).
13 years ago
I'm working on some new code to practice on loops and remainders (and thus divisors). I finished the darn thing, and I can follow it to the very end, but it seems to be stuck somewhere in the loop, since it never outputs the data after compiling an running the program.



My naming is atrocious, i know! Hopefully the //comments can help lead you to the problem though!

Also, if you know a way you can make this more elegant, for example, using if else, if then, or for. Feel free to point it out. Right now its all a blur to me!
13 years ago
Got it! I deleted the quarter, dime, nickle, and penny variables, and instead plugged in the value times 100 where the variables used to be. If I divide that at the end by 100, it gives me a nice round number ^.^
13 years ago
oh my... just a tad bit over my current skill
13 years ago
Thanks, I'll google up those terms and see what I can learn!
13 years ago
is there a way to restrict the place value of a double variable? I'm writing a change counting program, and I'm getting a number out to the bajillionth place. For reference, here is the code



TextIO is an input/output external class I'm using, designed by David J. Eck. I doubt its the problem, but the coding for it is currently above my skill.

I ran multiple searches, but google fails me on this one guys
13 years ago
Thank you very much for pointing out my amateur move! It works perfectly now (besides the whole decimal thing, but I think changing the variables to int, instead of double will fix that!)
13 years ago
First of all, hello! I'm currently on a path of java enlightenment. I am attempting to learn Java by doing, which I feel fits my learning style excellently!

The only problem is I get lots of errors and warning, and while most I can fix, some I cannot figure out. I am currently working on a piece of code that will allow me to see the result of 2 dice being thrown, both their single values and their summation.



when I compile this, I get not warnings or errors, so I'm assuming the syntax is right. However, when I attempt to run this program (through cmd) I get this doozy:

Exception in thread "main" java.lang.NoClassDefFoundError: dice (wrong name: Dice)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.define.ClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassloader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)

...it goes on for about 7 more lines of stuff I don't understand and then ends with

Could not find the main class: dice. Program will exit.



So, I searched the forums found something with a similar error, but their problem was not having a main() function. I'm fairly certain the "public static void main(String[] args)" is my main () function. The error itself led me to believe I had forgotten to define this program as a Class, but its clearly labeled as Dice.

Any help you could give to point me in the right path is much appreciated! I am very new with java, so please bear through my ignorance
13 years ago