By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

illegal start of type and identifier error

P: 1
I'm getting these 2 errors and haven't got a clue whats causing them please

java 43: illegal start of type
for (i=0;i< Number_of_squares; i++)

java 215 identifier expected
}


heres the whole code
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class areaCalculation3
  4. {
  5.     // Set-up data input 
  6.  
  7.     Scanner data_input = new Scanner(System.in); 
  8.     public static double valid_data(String input_message) 
  9.     Scanner data_input = new Scanner(System.in); 
  10.     boolean valid_data = false; 
  11.     double data = 0; 
  12.  
  13.     do 
  14.     { 
  15.         System.out.print(input_message); 
  16.  
  17.         try 
  18.         { 
  19.             data = data_input.nextDouble(); 
  20.             valid_data = true; 
  21.         } 
  22.         catch (InputMismatchException e) 
  23.         { 
  24.     // Remove invalid data 
  25.     data_input.next(); 
  26.     // Output error message 
  27.     System.out.println("Invalid input, please enter a valid number."); 
  28.         } 
  29.  
  30.     } while (! valid_data); 
  31.  
  32.     return data; 
  33.     } 
  34.  
  35.     //method for the area of the square
  36.  
  37.     public static void area_of_square(String area);
  38.     // Declare variables 
  39.             double Length, Number_of_squares, Increment, Area, value_of_increment, i; 
  40.             String area;
  41.  
  42.         for (i=0;i< Number_of_squares; i++) 
  43.         { 
  44.             Area = Length * Length; 
  45.  
  46.             System.out.printf("%nLength of square: %f", Length); 
  47.             System.out.printf(", Area of square: %f", Area); 
  48.  
  49.             Length = Length + Increment; 
  50.         }
  51.             {
  52.             Scanner data_input = new Scanner(System.in); 
  53.  
  54.             // Declare variables 
  55.             double Length, Number_of_squares, Increment, Area, i; 
  56.             string area;
  57.  
  58.             Length = valid_data("Please enter the length: "); 
  59.  
  60.             Number_of_squares = valid_data("Please enter the number of triangles"); 
  61.  
  62.             Increment = valid_data("Please enter the increment: "); 
  63.  
  64.             for (i=0;i<Number_of_squares;i++) 
  65.             { 
  66.                 Area = Length * Length; 
  67.                 System.out.printf("%nLength of square: %f", Length); 
  68.                 System.out.printf(", Area of square: %f", Area); 
  69.  
  70.                 Length = Length + Increment; 
  71.             } 
  72.             }
  73.         //Rectangle area method
  74.         public static void area_of_rectangle(String [] args)
  75.         // Set-up data input 
  76.         Scanner data_input = new Scanner(System.in); 
  77.  
  78.         // Declare variables 
  79.         double Length, Width, Number_of_rectangles, Increment, Area, i; 
  80.         String area;
  81.             Length = valid_data("Plase enter the length: "); 
  82.             Width=    valid_data("Plase enter the width: "); 
  83.  
  84.             Number_of_rectangles = valid_data("Please enter the number of  rectangles"); 
  85.  
  86.             Increment = valid_data("Please enter the increment: "); 
  87.  
  88.             for (i=0;i<Number_of_rectangles;i++) 
  89.             { 
  90.                 Area = Length * Width; 
  91.  
  92.                 System.out.printf("%nLength of rectangles: %f", Length); 
  93.                 System.out.printf("%nWidth of rectangles: %f", Width);
  94.                 System.out.printf(", Area of rectangles: %f", Area); 
  95.  
  96.                 Length = Length + Increment;
  97.             } 
  98.     } 
  99.  
  100.     //Area of Triangle method
  101.     public static void area_of_triangle(String [] args) 
  102.     { 
  103.         // Set-up data input 
  104.         Scanner data_input = new Scanner(System.in); 
  105.  
  106.         // Declare variables 
  107.         double Base, Height, Number_of_triangles, Increment, Area, i; 
  108.         String area;
  109.  
  110.         Length = valid_data("Plase enter the base: "); 
  111.         Height = valid_data("Plase enter the Height: "); 
  112.         Number_of_triangles = valid_data("Please enter the number of triangles"); 
  113.  
  114.         Increment = valid_data("Please enter the increment: "); 
  115.  
  116. for (i=0;i<Number_of_triangles;i++) 
  117.     { 
  118. Area = Base/2 * Height; 
  119.  
  120. System.out.printf("%nBaseof triangle: %f", Base); 
  121. System.out.printf(", Area of square: %f", Area); 
  122.  
  123. Base = Base + Increment; 
  124. Height= Height+Increment;
  125.     } 
  126.     } 
  127.  
  128.         //Circle method
  129.         public static void area_of_circle(String [] args) 
  130.      { 
  131.          // Set-up data input 
  132.          Scanner data_input = new Scanner(System.in); 
  133.  
  134.          // Declare variables 
  135.          double Radius, Number_of_circles, Increment, Area, i; 
  136.  
  137.         Radius = valid_data("Plase enter the radius: "); 
  138.  
  139.         Number_of_circles = valid_data("Please enter the number circles"); 
  140.  
  141.         Increment = valid_data("Enter the increment: "); 
  142.  
  143.         for (i=0;i<Number_of_circles;i++) 
  144.         { 
  145.     Area = Radius * Radius * 3.1415927; 
  146.  
  147.     System.out.printf("%nRadius of Circle: %f", Radius); 
  148.     System.out.printf(", Area of square: %f", Area); 
  149.  
  150.     Radius = Radius + Increment; 
  151.         } 
  152.      } 
  153.             public static void main (String [] args)
  154. {    //Declare variables
  155.      int user_choice;
  156.     boolean quit = false;
  157.     String continue_pref;
  158.  
  159.     //Menu System
  160.     do
  161.     {
  162.         Scanner data_input = new Scanner(System.in);
  163.  
  164.         System.out.printf ("%n%nPlease choose one of the following:%n%n");
  165.             System.out.println("1.    Calculate The Area Of A Square");
  166.             System.out.println("2.    Calculate The Area Of A Rectangle");
  167.             System.out.println("3.    Calculate The Area Of A Triangle");
  168.             System.out.println("4.    Calculate The Area Of A Circle");
  169.             System.out.printf("5.     Quit %n%n Please make your choice:  ");
  170.  
  171.             try 
  172.             { 
  173.                 user_choice = data_input.nextInt(); 
  174.             } 
  175.             catch (InputMismatchException e) 
  176.             { 
  177.                 // Remove invalid data 
  178.                 data_input.next(); 
  179.                 // Make data an invalid value 
  180.                 user_choice = -1; 
  181.             } 
  182.  
  183.             //Get choice from user
  184.             user_choice = data_input.nextInt();
  185.  
  186.             //Linking menu to methods
  187.             switch(user_choice)
  188.             {
  189.             case 1:
  190.                 area_of_square(args);
  191.                 break;
  192.             case 2:
  193.                 area_of_rectangle(args);
  194.                 break;
  195.             case 3:
  196.                 area_of_triangle(args);
  197.                 break;
  198.             case 4:
  199.                 area_of_circle(args);
  200.                 break;
  201.             case 5: 
  202.                 quit = true;
  203.                 break;
  204.             default:
  205.             System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
  206.             }
  207.     if (quit= true)
  208.     {
  209.     System.out.printf(" %n Typing error. %n Please Enter A Number Between 1 - 5.");
  210.     } 
  211.     } while (continue_pref.equalsIgnoreCase("N"));
  212. }
  213. }
  214.  
thanks in advance for any help
Mar 15 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
you appear to have a ; on the end of
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area);
  2.  
should it be?
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area)
  2. {
  3.     // Declare variables 
Mar 15 '07 #2

N002199B
P: 41
you appear to have a ; on the end of
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area);
  2.  
should it be?
Expand|Select|Wrap|Line Numbers
  1. public static void area_of_square(String area)
  2. {
  3.     // Declare variables 

Oh yes . I had missed that semi-colon also. Fter removing it, u may still get an eror about the variable "i" not having been declared. ie: variable i cannot be resolved. on the for loop try

Expand|Select|Wrap|Line Numbers
  1.  for(int i=0; i<bla bla bla){
This shd work
Mar 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.