# Thread: [Help] Arrays and MagicSquare

1. ## [Help] Arrays and MagicSquare

Hi.. I need your help in jcreator with Arrays...
ive been working on these programs but still cant get it..

Activity 1:
Create class ArrayApp with 20 elements. The program must ask the user to input an element to search for and prints message " Found[search key] " Then prints the data eliminating the searched element. Otherwise, print "[search key] not Found".
Below is the sample output you should acquire.

Output:

77 99 44 55 22 88 11 0 66 33
Found 66.

77 99 44 55 22 88 11 0 33
************************************************** ***********
Activity 2:
Create a MagicSquare with [7][7] dimension
The magic Square should display a magic square below

Output:

28 19 10 1 48 39 30
29 27 18 9 7 47 38
37 35 26 17 8 6 46
45 36 34 25 16 14 5
4 44 42 33 24 15 13
12 3 43 41 32 23 21
20 11 2 49 40 31 22

2. Is this question posted elsewhere?
Help in Multidimensional Arrays :(

3. Member
Join Date
Nov 2011
Posts
1
Rep Power
0

public class ArrayApp {

long[] arrayElems;
int numElements;
public ArrayApp() {
this(10);
}

public ArrayApp(int nElems) {
arrayElems = new long[nElems];
numElements = 0;
}

arrayElems[0] = 77;
arrayElems[1] = 99;
arrayElems[2] = 44;
arrayElems[3] = 55;
arrayElems[4] = 22;
arrayElems[5] = 88;
arrayElems[6] = 11;
arrayElems[7] = 00;
arrayElems[8] = 66;
arrayElems[9] = 33;
numElements = 10;
}

public void displayElements() {

System.out.println();
System.out.print ("");
for (int j=0; j<numElements; j++) {
System.out.print(arrayElems[j] + " ");
}
System.out.println("");
}

public void searchElement(long sKey) {
System.out.println();
int j;
for (j=0; j<numElements; j++) {
if (arrayElems[j] == sKey) {
break;
}
}
if (j == numElements) {
} else {
System.out.println("Found " + sKey);
}
}
public void deleteElement(long dKey) {
System.out.println();
int j;
for(j=0; j<numElements; j++) {
if(arrayElems[j] == dKey) {
break;
}
}
if (j == numElements) {
} else {
for (int k=j; k<numElements; k++) {
arrayElems[k] = arrayElems[k+1];
}
numElements--;
}
}
public static void main(String[] args) {
ArrayApp arrayApp = new ArrayApp(20);
arrayApp.displayElements();
arrayApp.searchElement(66);
arrayApp.searchElement(34);
arrayApp.deleteElement(55);
arrayApp.deleteElement(34);
arrayApp.displayElements();
}
}

4. ## Re: [Help] Arrays and MagicSquare

What is the purpose of your post? What is this code supposed to do?
If you have a question you should start your own thread and not hijack someone else's thread.