473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Can some one tell me where the problem is the program fails to compile

thatos
105 100+
I would like to design a method which when given an array it returns an array which it's elements are from the initial array greater than the average of all numbers in that array;
the method average(int array[]) works properly here is the problem

here is that method
Expand|Select|Wrap|Line Numbers
  1.   public static int[] small(int array[]){
  2.     double s1 = average(array);
  3.     int length = 0;
  4.  
  5.  
  6.     //Finds how many numbers are greater than the average
  7.     for(int j:array){
  8.       if (j > s1){
  9.         length++;
  10.       }
  11.     }    
  12.     int initial = 0;
  13.     int array2[] = new int[length];
  14.     void add(int p){
  15.       array2[initial] = p;
  16.       initial++;
  17.     }
  18.     for (int j:array){
  19.       if (j > s1)
  20.          array2.add(j);        
  21.     }
  22.     return array2;
  23.   }
  24.  
Your reply will be appreciated
Apr 24 '08 #1
3 1040
JosAH
11,448 Expert 8TB
You're trying to define a local method add() in that other method. The compiler
will and shall protest against that.

kind regards,

Jos
Apr 24 '08 #2
thatos
105 100+
Yes, do you have any suggestions how can I go about this because I need that method or I won't be able to accomplish my task or can you tell me what to do please .


You're trying to define a local method add() in that other method. The compiler
will and shall protest against that.

kind regards,

Jos
Apr 24 '08 #3
BigDaddyLH
1,216 Expert 1GB
Yes, do you have any suggestions how can I go about this because I need that method or I won't be able to accomplish my task or can you tell me what to do please .
When you define methods in a class, you define them one after another:

Expand|Select|Wrap|Line Numbers
  1. class Example {
  2.     void method1 () {
  3.  
  4.     }
  5.  
  6.     void method2() {
  7.  
  8.     }
  9. }
You don't nest their definitions:

Expand|Select|Wrap|Line Numbers
  1. class Example {
  2.     void method1 () {
  3.          void method2() {
  4.  
  5.         }
  6.     }
  7. }
Do you know about Sun's Java tutorial? http://java.sun.com/docs/books/tutorial/java/index.html
Apr 24 '08 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
1
by: Amit Gangrade | last post by:
I am trying to make a configure script for a c++ library . The library can be compiled with some optional header files,depending on the users decision . So basically I need to check for the headers...
6
by: Charlie | last post by:
Dear all, I am stuck on this problem, couldn't find an answer on any C++ book in the bookshop. Following is a cut of my program, and its error message:...
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
9
by: ludocluba | last post by:
Hello, here is my problem: I have 3 files: main.c toto.c toto.h: ----------------------------------------------------------- toto.h: #ifndef _toto_h #define _toto_h int var; void test(void);...
0
by: Domenic Albano | last post by:
Any ideas truly appreciated. I wrote a mixed mode dll component in VC 7.1 which compiles with no errors and works great. It is being consumed by a C# program, which when it compiles again, works...
0
by: drken567 | last post by:
I'm trying to execute a command line from my C++ .NET code/WinXP. The program (call it myprog.exe) is located in a directory (C:\mypath) which is included in the system 'path' environment variable....
3
by: Marco Shaw | last post by:
I've got some C# code to create a custom PowerShell cmdlet with these statements: .... using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; .... ...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.