Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    9
    Rep Power
    0

    Unhappy [Help] Arrays and MagicSquare

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

    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. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

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

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

    Default Sorry late reply " i have a answer for your activity one"

    public class ArrayApp {

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

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

    public void loadArray() {
    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.loadArray();
    arrayApp.displayElements();
    arrayApp.searchElement(66);
    arrayApp.searchElement(34);
    arrayApp.deleteElement(55);
    arrayApp.deleteElement(34);
    arrayApp.displayElements();
    }
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default 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.

Similar Threads

  1. arrays and multidimensional arrays
    By belfast09 in forum New To Java
    Replies: 5
    Last Post: 06-14-2011, 01:28 PM
  2. Arrays
    By Latanyar in forum New To Java
    Replies: 12
    Last Post: 10-20-2010, 10:34 AM
  3. Arrays
    By ayiliath in forum New To Java
    Replies: 4
    Last Post: 10-18-2010, 09:01 PM
  4. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 10:32 AM
  5. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •