0

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.

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Zaad
0

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

0

Do these alterations and it will work
Line 24

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

and in line 34

}
0

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;
	}
}
0

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

Edited by Zaad: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.