Stuck again. could use some help from the community.

// This program accepts a height and a radius from the user
// It uses a subroutine to calculate the volume of the cone
// The formula is v = (3.14 * r * r * h)/3




public class Midterm
{
	public void main(String args[])
	{
		double r;
		int h;
		String reply;

		while(true)
		{

		System.out.print("Enter radius: ");
		r = Keyboard.readInt();
		system.out.print("Enter height: ");
		h = keyboard.readInt;

		System.out.println("The volume of the cone is: ") + CylVol);

		System.out.print("Play again? (y/n) ");
		reply = Keyboard.readDouble();
		
		if(reply.equals("n"))
			break;
		
		}



	static double CylVol(int v)
	{
		int vol;
		Vol = (3.14 * r * r * h)/3;
		return vol;
	}
}

Errors;
--------------------Configuration: <Default>--------------------
\\filesvrcls\2011\stawil\Java\midterm.java:24: not a statement
System.out.println("The volume of the cone is: ") + CylVol);
^
\\filesvrcls\2011\stawil\Java\midterm.java:24: ';' expected
System.out.println("The volume of the cone is: ") + CylVol);
^
\\filesvrcls\2011\stawil\Java\midterm.java:36: illegal start of expression
static double CylVol(int v)
^
3 errors

Process completed.

Recommended Answers

All 4 Replies

Check the brackets! You have mismatching brackets. If you are using Eclipse or NetBeans it should indicate that.

Do these alterations and it will work
Line 24

System.out.println("The volume of the cone is: " + CylVol);

and in line 34

}

I added the decleared into the sub rutine because i was getting many errors without it. Now when i compile i get this error:

--------------------Configuration: <Default>--------------------
\\filesvrcls\2011\stawil\Java\midterm.java:36: ';' expected
static double CylVol(int v)
^
1 error

Process completed.

// This program accepts a height and a radius from the user
// It uses a subroutine to calculate the volume of the cone
// The formula is v = (3.14 * r * r * h)/3




public class Midterm
{
	public void main(String args[])
	{
		double r;
		int h;
		String reply;

		while(true)
		{

		System.out.print("Enter radius: ");
		r = Keyboard.readInt();
		system.out.print("Enter height: ");
		h = keyboard.readInt;

		System.out.println("The volume of the cone is: " + CylVol);

		System.out.print("Play again? (y/n) ");
		reply = Keyboard.readDouble();
		
		if(reply.equals("n"))
			break;
		
		}

	}

	static double CylVol(int v)
		double r;
		int h;
		String reply;
	
	{
		int vol;
		Vol = (3.14 * r * r * h)/3;
		return vol;
	}
}

Delete the bracket in line 41

{

and in line 36 add the bracket

static double CylVol(int v) {

ALso it won't help u by adding the declaration of h and r into the subroutine instead move those to the class level i.e. befor the main method and delete the other declerations of r and h inside the methods

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.