• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Math.pow

 
Shawn Rizzo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you lost me. "name it distinctly from the class name." would that be
public class CalculateFunction (int x)(int j); ?
 
Shawn Rizzo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Shawn Rizzo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, thank-you. I changed up my name, that's a cool policy actually. I'm working on another program now.. thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic