Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Understand Errors

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Hey all,

I just finished taking a four day Java course and so I'm trying to refresh and I'm getting some errors. I wrote a very simple class that is supposed to find volume:

class findVolume {
public static void main (String args[]) {
if (args.length != 3) {
System.out.println("Please give me a value for Length, Width and Depth.");
}
else {
computeVolume(args[0], args[1], args[2]);
}

public static int computeVolume(int argLength, int argWidth, int argDepth) {
int myLength = argLength;
int myWidth = argWidth;
int myDepth = argDepth
int myVolume = argLength * argWidth * argDepth;

return myVolume;
}
}
}

Unfortunately, I'm getting two errors:

findVolume.java:10: illegal start of expression
public static int computeVolume(int argLength, int argWidth, int argDepth) {
^
findVolume.java:17: ';' expected
}
^
2 errors

Can anyone help?

Thanks,

- MT
 
You're missing a close-curly ( } ) to end your 'main'.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Ah... I think I got it now. Here is the finished code:

class findVolume {
public static void main (String args[]) {
if (args.length != 3) {
System.out.println("Please give me a value for Length, Width and Depth.");
}
else {
int theLength = Integer.parseInt(args[0]);
int theWidth = Integer.parseInt(args[1]);
int theDepth = Integer.parseInt(args[2]);

int finalVolume = computeVolume(theLength, theWidth, theDepth);

System.out.println("The volume is " + finalVolume);
}

}

public static int computeVolume(int argLength, int argWidth, int argDepth) {
int myLength = argLength;
int myWidth = argWidth;
int myDepth = argDepth;
int myVolume = argLength * argWidth * argDepth;

return myVolume;
}
}

Must my methods always be outside of Main?

- MT
 
Please post standard Java questions in forum269 - this forum (as the name implies) is for J2EE questions !!!

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
A method definition is an entity that cannot be inside another method definition, bot just main.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top