Update! More help? Java homework. I'm getting pissed

IronOxide

Senior member
Feb 24, 2003
581
0
0
I can't figure out how to get a number raised to a variable power. 2^x doesn't work, and I couldn't find anything on the api. Anyone that knows java wanna help? Thanks!
 

Regs

Lifer
Aug 9, 2002
16,665
21
81
I never quite understood the purpose of a for loop/ for while loop ect..

Just one of those things I want to figure out before even reading a java book.
 

TerryMathews

Lifer
Oct 9, 1999
11,464
2
0
Originally posted by: Regs
I never quite understood the purpose of a for loop/ for while loop ect..

Just one of those things I want to figure out before even reading a java book.

In english, a for loop says

given x variable, while a comparison of x is true, do whats in the brackets and then do this line

For(Int variable = 1; variable != 2; variable++)
{
cout << "See, I'm not so hard to understand" << endl;
}

The program hits the for, and does the first part of the paren (Int variable = 1;) in this case, it defines an integer variable and sets it equal to 1.

Then it checks if the second is true. variable != 2. variable == 1 and 1 < 2 so this is true. So the program executes what's in the squigglies (cout << "See, I'm not so hard to understand." << endl;) and then the last item in the parens (variable++).

The program then checks the second part again. It's false this time, so the loop terminates.

It really makes more sense if you play with it in a debugger. You can watch exactly how the language steps through each part, and why.
 

IronOxide

Senior member
Feb 24, 2003
581
0
0
Thanks you guys, I knew you guys could help me out. I got one more question though (at least for now). How do I convert a string to an int? Isn't it mystring.parseint() or something?
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
Originally posted by: IronOxide
Thanks you guys, I knew you guys could help me out. I got one more question though (at least for now). How do I convert a string to an int? Isn't it mystring.parseint() or something?

string s="535";
int i = Integer.parseInt(s);

doubles would be...
Double.parseDouble(string s);

same story for Float and Long too.
 

SaturnX

Diamond Member
Jul 16, 2000
3,415
0
76
Java 2 Platform API

This site might come in handy, it sure did for me last year in high school, covers all the classes, and libraries that you'd ever use, just it won't help you if you're going to be using 1.4 API calls.. since it's the 1.3 API Documentation.

Just search up a class, and then check the methods and all.

Hope this helps,

--Mark