Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mcmacmcmac

macrumors member
Original poster
Oct 2, 2007
86
0
My first java program.. I keep getting this error msg when I compile..

'{' expected
public class AreaOfShapes.java
^
1 error

Tool completed with exit code 1

But I don't think I'm missing a { .. Can someone tell from this:

import java.util.Scanner; // program uses class Scanner


public class AreaOfShapes2.java
{

public static void main( String args[] )
{

System.out.println("Student Name: Bob\nStudent ID: 999\n\n");

// create scanner object to obtain input from user
Scanner input = new Scanner(System.in);

// display choices of shapes for the user to choose from
System.out.println("Choose one of the following options: \n1 for calculating the area of a circle");
System.out.print("2 for calculating the area of a square\n3 for calculating the area of a rectangle\nEnter your choice:");
int choice = input.nextInt(); // read the choice from user


if (choice > 3) // display an error message indicating an invalid selection
System.out.println("Your selection is invalid. Please try again.");
else if (choice == 1) // calculate the area of a circle
{
System.out.print("\nEnter the radius of the circle:");
double radius = input.nextDouble();
double area = (3.14 * radius * radius);
System.out.printf("The area of the circle is %.2f\n", area);
}
else if (choice == 2) // calculate the area of a square
{
System.out.print("\nEnter the length of a side of the square:");
double side = input.nextDouble();
double area = (side * side);
System.out.printf("The area of the square is %.2f\n", area);
}
else if (choice == 3) // calculate the area of a rectangle
{
System.out.print("\nEnter the length of the rectangle: ");
double length = input.nextDouble();
System.out.print("Enter the width of the rectangle: ");
double width = input.nextDouble();
double area = (width * length);
System.out.printf("The area of the rectangle is %.2f\n", area);
}

} // end method Main

} // end class AreaOfShapes2
 

italiano40

macrumors 65816
Oct 7, 2007
1,080
0
NY
add a "}" at the end of the program and it should work

:apple:

and next time use
Code:
to show code
 

mcmacmcmac

macrumors member
Original poster
Oct 2, 2007
86
0
that didn't work but i figured it out.

i put .java at the end of line below

public class AreaOfShapes2.java



Thank you anways
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.