Help n Java Coding...

Associate
Joined
6 Oct 2007
Posts
1,014
Location
Liverpool
1- can sum1 make head nor tail ov how this is written out?

----------------------------
If the user chooses to calculate the area of squares, an ‘area_of_squares’ method will ask for the following data which will be used to calculate and display the areas of the squares:

First square side length (L)
Number of further square areas to calculate (N)
Square size increment (I)

e.g. If the user enters L = 5, N = 2, I = 2 then three square areas of
L = 5, L = 7 and L = 9 will be calculated and displayed.

The formula for calculating the area of a square is:

Area = L * L

--------------------------

this makes no sence really... so if anyone can enlighten me =D

(I have to have a calculation coded in java by friday :confused::()

thanx
 
This is how I would do it:

Code:
public int area_of_squares(int len, int num, int inc){
    int area = 0;
    int length = len;
    for (int i = 0; i < num+1; i++) {
        area += length * length;
        length += inc;
    }
    return area;
}

It's fairly basic code so try and understand how it works, the maths involved in it is very simple.
 
As you say the method will ask do you mean reading input? If so have a squint at the Scanner class (dor a command line env), or an input JDialogBox (if you're in a swing env) from the API.
 
Back
Top Bottom