File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Math.pow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math.pow" Watch "Math.pow" New topic
Author

Math.pow

Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
hello. I keep getting the following errors:
";" expected for lines 8 & 10, do I not have them in the right place? hopefully a new set of eyes will be able to help thanks in advance, here's the program.

public class calculateFunction
{

public int calculateFunction (int x);
{

int y=0
y=(int)(x+(x*x) + Math.pow(2,x));
return y

}

public void printStars ();
{
for (int j; j < 10; ++j);
{

int y = calculateValue(j);
y/=10;
System.out.println("PrintFor: +j");
for (int I=0;i<y;i++)
System.out.print("*");
System.out.println ("\n\n");
}
}

public static void main (String[] args);
{
calculateFunction cal = new calculateFunction ();
Cal.printStars();
}
}
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
"dungle", welcome to the ranch. You may get a note from the moderators about using a fictitios name.

public class calculateFunction

By convention, class names should be capitalized

public int calculateFunction (int x);

Extra semicolon.


int y=0
return y


Semicolons missing at the end of these statements.


public void printStars ();

Extra semicolon.


for (int I=0;i<y;i++)

By convention, local variables start with a lower case.


calculateFunction cal = new calculateFunction ();
Cal.printStars();


Java is case sensitive, your object "Cal" will not be recognized.

for (int j; j < 10; ++j);

Local variable j is not initialized.


You've got some other problems, but let's do few steps at a time. Please use the "CODE" UBB when posting code in the future -- it'll make it more readable. You may also explore if your IDE has the "autoformat" feature -- it will sprinkle the spaces and line up the braces for you.
[ June 18, 2005: Message edited by: John Smith ]
Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
wow, I followed your advice, unless I misunderstood, and I jumped from 1 to 8 errors. here is what I compiled with the errors.

public class CalculateFunction
{

public int CalculateFunction (int x)
{

int y=0;
y=(int)(x+(x*x) + Math.pow(2,x));
return y;

}

public void printStars ()
{
for (int j; j < 10; ++j);
{

int y = calculateValue(j);
y/=10;
System.out.println("PrintFor: +j");
for (int I=0;i<y;i++)
System.out.print("*");
System.out.println ("\n\n");
}
}

public static void main (String[] args);
{
calculateFunction cal = new calculateFunction ();
cal.printStars();
}
}
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
You are almost there.

for (int j; j < 10; ++j);

Extra semicolon.

int y = calculateValue(j);

Local variable j is not declared or initialized before it's used here.

for (int I=0;i<y;i++)

Java compiler is unforgiving. You can't hope to get away with something like this.

calculateFunction cal = new calculateFunction ();

You changed the name of your class, but you still refer to the old name of the class.
Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
thanks for your help, I compiled it again and I get an error saying ";" expected again at line 5, and it's already there.

public class CalculateFunction
{

public int CalculateFunction (int x)
(int j);
{

int y=0;
y=(int)(x+(x*x) + Math.pow(2,x));
return y;

}

public void printStars ()
{
for (int j; j < 10; ++j)
{

int y = calculateValue(j);
y/=10;
System.out.println("PrintFor: +j");
for (int I=0;i<y;i++)
System.out.print("*");
System.out.println ("\n\n");
}
}

public static void main (String[] args);
{
CalculateFunction cal = new CalculateFunction ();
cal.printStars();
}
}
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

public int CalculateFunction (int x)
(int j);
{


The (int j) doesn't belong here. If your intent is to pass two parameters, the format for that is methodName(int p1, int p2). I am not sure that it is your intent, however. Since this method has the same name as the class, perhaps you want it to be a constructor. If that's the case, it should not have a return type, and there should be very little code inside. Now, if it's a regular method, name it distinctly from the class name.
Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
you lost me. "name it distinctly from the class name." would that be
public class CalculateFunction (int x)(int j); ?
Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
thx for your help, I'm still not getting it. I think I need to sleep and attack it again tomorrow. thx again. -shawn
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11164
    
  16

I'm surprised a moderator hasn't told you to change your screen name yet. JavaRanch policy is that it must be a real (sounding) first and last name. It doesn't have to be your ACTUAL name, but you should at least pretend it is here (i.e. don't chose a screen name of Tom Smith, then sign your posts as Fred).

Anyway, what John is saying is that it's unclear what you're trying to do with your function. If the function is a contructor, then it should not have a return type (the "int" in your "public int CalculateFunction").

if it's NOT a contructor (and i don't think you mean for it to be one), it should have some name OTHER than that of the class name... something like

public int doCalculation();

now, you can pass several paramters into any funtion (contructor or otherwise), but they ALL go into the same set of parentises. so you could have



hope that helps some...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Shawn Rizzo
Greenhorn

Joined: Jun 18, 2005
Posts: 9
okay, thank-you. I changed up my name, that's a cool policy actually. I'm working on another program now.. thanks again
 
Don't get me started about those stupid light bulbs.
 
subject: Math.pow
 
Similar Threads
GUI display(rendering) problem
Same old problems
Method Overloading?
stars
Swaping Numbers