.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   ';' expected - Java (http://forums.bots-united.com/showthread.php?t=1869)

Zacker 04-06-2004 17:46

';' expected - Java
 
I know there arent many java coders in here, but I hope someone can help my anyway.

The compiler gives me this error with a "^" below the last bracket:

';' expected
stats_sum = styrke + intelligens + liv.liv()/10);



This is how the lines around look like:
//Tjek om stats er fair
public void stats()
{
double stats_sum;
stats_sum = styrke + intelligens + liv.liv()/10);
if(stats_sum!=30)
{
System.out.println("");
System.out.println("Intern programfejl - Stats for racen "
+ race + " er ikke fair");
System.out.println("");
}
}

The liv object gets initialized here:
//Liv
//Opret et objekt af klassen Liv
Liv liv = new Liv();


The liv method/function is here:
//Justerer eller returnerer spillerens liv
public int liv(int a)
{
if(a!=0)
{
//Giver spilleren a mere i liv, hvis a ikke er 0
liv = liv + a;
System.out.println("Du har nu " + liv + " i liv");
}
else
{
//Returnerer værdien af liv til den kaldende funktion
return liv;
}

}

MusicMan 04-06-2004 17:50

Re: ';' expected - Java
 
Hey, fellow Dane;)

*couldn't resist*:)

Zacker 04-06-2004 17:53

Re: ';' expected - Java
 
I am indeed danish!

Rick 04-06-2004 17:53

Re: ';' expected - Java
 
Ive never seen any other java code except this but shouldn't
Code:

      stats_sum = styrke + intelligens + liv.liv()/10);
be
Code:

      stats_sum = styrke + intelligens + liv.liv()/10;
I'm just guessing...

MusicMan 04-06-2004 17:58

Re: ';' expected - Java
 
Don't you mean:

stats_sum = styrke + intelligens + Liv.liv()/10); //notice the capital L in class Liv

because there doesn't seem to be a difference between your two code snippets.

Zacker 04-06-2004 18:11

Re: ';' expected - Java
 
You found it Rick, thanks for the quick reply!

MusicMan, nope the capital is not needed. I define the Liv class to be liv here:
Liv liv = new Liv();
1. word is variable type
2. word is variable name
3. word is for a new object
4. word is class name

MusicMan 04-06-2004 19:04

Re: ';' expected - Java
 
oh, now I see the difference:) you should not have the paranthesis at the end.

Huntkillaz 09-06-2004 12:12

Re: ';' expected - Java
 
java roxor :)

yeah downside about the compiler is it's not very accurate as to giving u whats exactly wrong....but basically the error is somewhere on that line...or rarely else where in code that calls the line

what is it ur trying to do with that code if u don't mind me asking


All times are GMT +2. The time now is 19:36.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.