473,761 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

illegal start of type and identifier error

1 New Member
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_squar es; 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
2 6631
horace1
1,510 Recognized Expert Top Contributor
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
41 New Member
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

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

Similar topics

1
1805
by: Grumble | last post by:
Hello everybody, (Disclaimer: I do not understand C++ templates.) I've tried to make a testcase from the original code. GCC 3.3.5 compiles with no warning, while GCC 3.4.3 rejects it. Could somebody tell me if it because the code is illegal, and GCC 3.4.3's stricter parser now rejects it, or is it some kind of regression?
2
17387
by: Gabrielle A. Grün | last post by:
Hi All, Does anyone know a way around the illegal reference of a non-static member? Thanks. iNHERITANCE HIERACY
134
9065
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
6
13582
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp cStepCurveEvaluator.cpp(14) : error C2296: '.*' : illegal, left operand
8
1917
by: LuB | last post by:
Is this somehow illegal? template<typename T> class A { public: private:
1
13052
by: Manish | last post by:
The code is as ... $folderlistfile = $path."xmlfile.xml"; /* <list> <details id="2"> <name>Books</name>
2
4629
by: mole40 | last post by:
Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me? import java.util.*; class ClockTalk { public static void main(String arguments) { //get current time and date Calenda now = Calendar.getInstance(); int hour = now.get(Calendr.HOUR_OF_DAY); int minute = now.get(Calendar.MINUTE);
2
13069
by: Lambda | last post by:
The code is simple: // Token.h #ifndef TOKEN_H #define TOKEN_H #include <vector> #include <string> class Token
3
9190
by: MrHenry007 | last post by:
Hello! I'm fairly new to c++ but I have been following tutorials and have created functions before, but not one using a string. I can't work out what the problem is here. The function is supposed to accept a file location, open the file, search for a phrase, and return a result if the certain phrase is found, otherwise return nothing. Then the result is written to a text file later in the program. Im using visual c++ 2008 and it is...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9988
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.