Drawing a maze from multidimensional array

Hi i have to create a maze using a properties file. The program has to be constructed using mvc. I have managed to read the information in the file using a string tokenizer and convert each value to an int. So my properties file is being read in the MazeStructure file which implements my model class etc. How do i get the maze structure to my gui and draw this in the shape of a maze.
Thanks

Here;-import java.awt.*;
import javax.swing.*;
public class Maze extends JFrame{
   int [][] mazePlan = {{0,0,0,0,0,1,0,0},
                        {0,0,0,1,1,1,0,0},
                        {0,0,0,1,0,1,0,0},
                        {0,0,0,1,0,0,0,0},
                        {0,0,0,1,1,1,1,0},
                        {0,0,0,0,0,0,1,0},
                        {0,0,0,0,0,0,1,0},
                        {0,0,0,0,0,0,1,0}};
   MazePanel mp = new MazePanel();
   public Maze(){
      setTitle("Maze");
          getContentPane().setLayout(new BorderLayout() );
      setSize(200, 200);
      setDefaultCloseOperation( EXIT_ON_CLOSE );
      getContentPane().add(mp);
   public class MazePanel extends JPanel{
      MazePanel(){
         setLayout(new GridLayout(mazePlan.length, mazePlan[0].length));     
         JPanel [][]wall = new JPanel[mazePlan.length][mazePlan[0].length];
         for(int i=0; i<mazePlan.length; i++){
            for(int j=0; j<mazePlan[0].length;j++){
               wall[i][j] = new JPanel();
               if(mazePlan[i][j]==0)
               wall[i][j].setBackground(Color.darkGray);
               else wall[i][j].setBackground(Color.lightGray);
               add(wall[i][j]);
   public static void main(String [] args){
      new Maze().show();
}

Similar Messages

  • Reading characters from a text file into a multidimensional array?

    I have an array, maze[][] that is to be filled with characters from a text file. I've got most of the program worked out (i think) but can't test it because I am reading my file incorrectly. However, I'm running into major headaches with this part of the program.
    The text file looks like this: (It is meant to be a maze, 19 is the size of the maze(assumed to be square). is free space, # is block, s is start, x is finish)
    This didn't paste evenly, but thats not a big deal. Just giving an idea.
    19
    5..................
    And my constructor looks like follows, I've tried zillions of things with the input.hasNext() and hasNextLine() to no avail.
    Code:
    //Scanner to read file
    Scanner input = null;
    try{
    input = new Scanner(fileName);
    }catch(RuntimeException e) {
    System.err.println("Couldn't find the file");
    System.exit(0);
    //Set the size of the maze
    while(input.hasNextInt())
    size = input.nextInt();
    //Set Limits on coordinates
    Coordinates.setLimits(size);
    //Set the maze[][] array equal to this size
    maze = new char[size][size];
    //Fill the Array with maze values
    for(int i = 0; i < maze.length; i++)
    for(int x = 0; x < maze.length; x++)
    if(input.hasNextLine())
    String insert = input.nextLine();
    maze[i][x] = insert.charAt(x);
    Any advice would be loved =D

    Code-tags sometimes cause wonders, I replaced # with *, as the code tags interprets # as comment, which looks odd:
    ******...*.........To your code: Did you test it step by step, to find out about what is read? You could either use a debugger (e.g., if you have an IDE) or system outs to get a clue. First thing to check would be, if the maze size is read correctly. Further, the following loops look odd:for(int i = 0; i < maze.length; i++) {
        for(int x = 0; x < maze.length; x++) {
            if (input.hasNextLine()) {
                String insert = input.nextLine();
                maze[x] = insert.charAt(x);
    }Shouldn't the nextLine test and assignment be in the outer loop? And assignment be to each maze's inner array? Like so:for(int i = 0; i < maze.length; i++) {
        if (input.hasNextLine()) {
            String insert = input.nextLine();
            for(int x = 0; x < insert.size(); x++) {
                maze[i][x] = insert.charAt(x);
    }Otherwise, only one character per line is read and storing a character actually should fail.

  • Drawing multidimensional array values

    Hi all,
    Need a bit of advice about turning a multidimensional 64x64 array (consisting of doubles) into a picture(!). The array contains a large number of 0.0 values (also known as a sparse matrix). For each value in the array i want to plot a little Rectangle whose colour varies as a function of its value (the values in the array are normalised and range between 0.0 and +1.0). The location of each rectangle on the screen (or Frame/ Panel or whatever) should reflect the position of the value in the array i.e. a value at index myArray[0, 0] should appear in the top left hand corner of the screen (or whatever).
    I am not sure which way is the best to achieve this and am eager to hear some suggestions.
    Thx in advance

    I started going mental last time I thought about picturing multdimensional arrays. I got thinking along the lines that a 2D array looks like a grid, a 3D would look kinda like a cube... but then you hit 4D, and so on, and .... well, my mind just doesn't look like that.
    I think maybe the best way to visualize a massive multidimensional array would be almost like a directory structure. ie. One item can expand to have a bunch more items, which would in turn have more items. This is basically what a MD array is. And if you're talking about having to display the data, this might not be a bad arrangement, since you could actually expand/collapse single elements of the array, like a directory tree, and thus have less data cluttering your screen at one time.

  • Problems making windchill chart using multidimensional arrays

    Alright i am doing a program for my java class. The book doesnt tell me much and the teacher didnt either cause we had a midterm to take. Alright in this program i have to write a java program that produces a wind chill chart with temperatures from 50 to -50 degrees f in steps of 10 degrees, with wind speeds from 5 to 50mph, in steps of 5mph. The following formula may be useful.
    windchill= ((10.45+6.686112 * sqrt(windspeed)- .447041 * windspeed)/22.034)*(temperature- 91.4) + 91.4
    use for statements in your program and a function to calculate the wind chill factor at a given temperature and wind speed.
    I know im gonna have to use multidimensional arrays to do this problem, unless someone has an easier way to do it. I am really stuck. I have this so far.
    import javax.swing.*;
    public class lab7
    public static void main( String args[] )
    int a[][] = {{5,10,15,20,25,30,35,40,45,50},
    {-50,-40,-30,-20,-10,0,10,20,30,40,50}};
    System.exit(0);
    I am not even sure if that is correct but the major problem is how can i get the program to show a table with the temperature on the x coordinate at the top the wind speed on the y axis and then having the program use those arrays to calculate the windchill and put that in the table. I am really stuck and i was wondering if u guys could give me a little push in the right direction. The book doesnt say much so thats why im asking.
    Thank you everyone.

    I have no clue what i am doing right now. I am so confused it isnt even funny. I am trying something new to see what happens. The decimalformat didnt do anything for me. I have the numbers i just want to be able to put them into a chart. I wish my teacher would actually teach, and the book actually say how to do stuff.
    This is my program:
    import java.text.DecimalFormat;
    public class lab7
    DecimalFormat twoDigits = new DecimalFormat ("0.00");
    static private double windchill(double s, double t) { 
    return (((10.45 + 6.686112 * Math.sqrt(s) - .447041 * s)/(22.034))*(t-91.4) + 91.4);};
    static void print(double s, double t)
    {   System.out.print(" "+windchill(s, t));};
    static private void printRow(double s)
    { // the speed is assumed constant  
    for (double t= -50; t <= 50; t+= 10) // loop over the temperature values
    print(s, t); // print a row value
    System.out.println();};
    static private void printChart()
    {   for (double s= 5; s <= 50; s+= 5)      
    printRow(s);};
    public static void main(String args[])
    for (double t= -50; t <= 50; t+= 10) // loop over the temperature values
    {System.out.print( "   " + t);};
    System.out.println();
    System.out.println();
    for (double s= 5; s<=50; s+= 5)
    {System.out.println(s);};
    printChart();
    I am probably way off and this program is due tomorrow and i am going nuts. I tried to do it during the week and it didnt work out to well.
    Here is what it is outputting.
    C:\cis260>java lab7
    -50.0 -40.0 -30.0 -20.0 -10.0 0.0 10.0 20.0 30.0 40.0 50.
    0
    5.0
    10.0
    15.0
    20.0
    25.0
    30.0
    35.0
    40.0
    45.0
    50.0
    -57.26056937082865 -46.747092046159025 -36.233614721489374 -25.720137396819737
    -15.2066600721501 -4.6931827474804635 5.820294577189159 16.333771901858796 26.84
    7249226528433 37.36072655119807 47.87420387586771
    -82.65748711959239 -70.3479052865236 -58.03832345345484 -45.728741620386074 -33
    .41915978731731 -21.109577954248536 -8.799996121179774 3.5095857118890024 15.819
    167544957764 28.128749378026534 40.4383312110953
    -98.80774164293763 -85.35599188035366 -71.90424211776966 -58.452492355185655 -4
    5.00074259260168 -31.54899283001768 -18.097243067433695 -4.645493304849694 8.806
    256457734293 22.25800622031828 35.70975598290227
    -110.17157107350803 -95.91615586321751 -81.66074065292699 -67.40532544263644 -5
    3.14991023234592 -38.894495022055395 -24.639079811764873 -10.38366460147435 3.87
    17506088161713 18.127165819106693 32.38258102939722
    -118.4766111010257 -103.63385218298993 -88.79109326495416 -73.94833434691841 -5
    9.105575428882645 -44.262816510846875 -29.42005759281112 -14.57729867477535 0.26
    54602432604065 15.108219161296176 29.95097807933194
    -124.60889848734033 -109.33245587861754 -94.05601326989475 -78.77957066117196 -
    63.50312805244914 -48.22668544372635 -32.950242835003564 -17.67380022628076 -2.3
    973576175579723 12.87908499116483 28.15552759988762
    -129.09477971074705 -113.50108949075079 -97.90739927075452 -82.31370905075829 -
    66.72001883076203 -51.12632861076577 -35.53263839076952 -19.93894817077326 -4.34
    5257950777011 11.24843226921925 26.842122489215498
    -132.2771986196876 -116.45844341320333 -100.63968820671906 -84.82093300023479 -
    69.00217779375052 -53.18342258726625 -37.36466738078198 -21.545912174297698 -5.7
    27156967813428 10.09159823867084 25.91035344515511
    -134.39436482483956 -118.42588074953267 -102.45739667422575 -86.48891259891886
    -70.52042852361197 -54.55194444830505 -38.58346037299816 -22.614976297691257 -6.
    646492222384367 9.321991852922537 25.29047592822944
    -135.61971729379445 -119.56457462803812 -103.50943196228181 -87.45428929652547
    -71.39914663076914 -55.34400396501283 -39.288861299256496 -23.233718633500175 -7
    .178575967743839 8.876566698012482 24.931709363768803
    C:\cis260>
    All i want it to do is look like this: im just gonna make numbers in between just say that there is numbers in that whole thing. What am i missing. Thanks everyone so far for everything, i just need a little more and it should be done.
    -50 -40 -30 -20 -10 0 10 20 30 40 50
    5 65 44 55 78 4 45 etc etc etc
    10
    15
    20
    25
    30
    35
    40
    45
    50

  • MultiDimensional Array or what????

    Hi Guys
    I have created an xml document that has this structure for
    each child:
    <work>
    <client>Telstar Records</client>
    <titled>Stargate Music.co.uk</titled>
    <thumb>images/thumbs/stargate_sm.jpg</thumb>
    <description>They were an up and coming band, i was a
    designer with a passion for 3d, they met fell in love and a new
    site was born. All it took was four press shots, one promo and a
    lot of imagination</description>
    <images>
    <image>images/large/telstar_sg_01.jpg</image>
    <image>images/large/telstar_sg_02.jpg</image>
    <image>images/large/telstar_sg_03.jpg</image>
    </images>
    <link>
    http://www.4zero1.co.uk/backupsites/stargate/index.html</link>
    </work>
    I have succesfully created buttons and used an associative
    array to compile the info for each button, woooooo aren't i
    clever!!!! I have set up a path to the <images> node, but I
    am stumped as to how i can pull the information from the
    'workImages' variable in my getworkData() function below .
    I need your help, as i would like to create buttons of the
    childnodes named <image> in the xml, above you can see that
    if i was successful i would have three buttons. My problem is
    relating the information to the buttons and making the buttons
    appear. I am not using a for loop as i would like to animate each
    button using a scripted tween. as in the makeButtons() function.
    Do I need to create a multidimensional array? I have included
    my code below, please don't get too lost in it, i hope someone can
    fathom it for me and give me an answer. My associative array is in
    the function getworkData(); My function to create the 'image'
    buttons is called portfolioImageCreator();
    Many thanks
    Jim

    You could use a table of records or a record group. They both achieve similar results but with very different syntax. I am not sure if there is any difference in performance.
    Record groups are good for certain things like lists populated from the database because built-ins are provided for manipulating them. If you are going to do the manipulation programatically, I personally find the syntax for tables of records less cumbersome than record groups. Learning the syntax for tables of records is also likely to be more universally useful to you as they have various uses such as passing data between procedures.
    In your situation the table of records needs to exist throughout the forms session rather than just during the execution of a single pl/sql block. The way to do that is create a program unit which is a package header without a body. Declare the table in there and it can be used throughout the form.
    However, if you only ever want to keep 5 records, it would probably be easier just to have 5 ordinary items in a control block on the null canvas (or global variables). When you want to record your new action just do:
    :item5 := :item4;
    :item4 := :item3;
    :item3 := :item2;
    :item2 := :item1;
    :item1 := :new_stuff;
    You could even construct the above in a loop using
    copy(name_in('item'||i),'item'i+i)
    but with only 5 items to manipulate, is it worth the bother ?
    Whatever method you decide to use, you are not going to get anything simpler than 5 little assignment statements.

  • Multidimensional array and chars

    Hi again,
    My apologies in advance if i can't word my question that well, i will try and be as clear and succinct as possible and hopefully for this newbie you can apprehend what i'm trying to figure out if i come up short.
    I'm trying to write a rather large control statement with a while loop and several nested ifs inside it that ultimately returns a single character after all is said and done, and then continually concatenates that character to a string which will eventually be output to a file. The part i'm stuck at is after i've changed the two letter characters into their ASCII values. I need to make the program take those two ASCII values and use them as a reference to a character in a multidimensional array of alphabetic characters, and then that character will be what is returned at the end.
    Here's the method, thanks in advance for your time.
    public String encode( String cipherKey )
            String textToEncode = input.next();
            String encodedText = " ";
            cipherKey = cipherKey.toUpperCase();
            textToEncode = textToEncode.toUpperCase();
            openFiles();
            int numberOfChars = textToEncode.length();
            int cipherPos = 0;
            int cipherLength = cipherKey.length();
            while (input.hasNext())
                for ( int count = 0; count < numberOfChars; count++ )
                    if (Character.isLetter(textToEncode.charAt(count)))
                        cipherPos %= cipherLength;
                        int xChar = (int) textToEncode.charAt(cipherPos);
                        int yChar = (int) textToEncode.charAt(count);
                        xChar -= 65;
                        yChar -= 65;
                        if ((xChar >= 0) && (xChar <= 25))
                            if ((yChar >= 0) && (yChar <= 25))
                        return ' ';
                     encodedText = encodedText +
        return encodedText; 
        }As you can see towards the end there are some incomplete statements where i became lost.

    its there, i couldnt c&p the whole program because it went over my character limit. Yeah it did compile but couldn't invoke my encode method without a NullPointerException.
    Here are the other methods in the class....
        public String setSource( String in )
            source = in;
            return source;
         Sets the value of the output file
         * @param out A <code>String</code> value representng name of output file.
         * @see #setSource
        public String setDestination( String out )
            destination = out;
            return destination;
         * Method to open both input and output files, and to test for exceptions
         * @see #encode
         * @see #decode
        private void openFiles()
        File inputFile = new File(source);  //Creates new file object from source file
        File outputFile = new File(destination);  //Creates new file object from destination file
            /* Tests whether input file exists and if so enables the Scanner
             * to read the data in from the source file. Catches SecurityException and
             * FileNotFoundException amd prints appropriate messages to user.
            if (inputFile.exists())
                try
                    input = new Scanner( new File( source ) );
                    FileReader reader = new FileReader(inputFile);
                    BufferedReader BufferIn = new BufferedReader(reader);
                catch ( SecurityException securityException )
                    System.err.println("You do not have read access to this file.");
                    System.exit( 1 );
                catch ( FileNotFoundException filesNotFoundException )
                    System.err.println("Error: File does not exist.");
                    System.exit( 1 );         
            /* Tests whether output file exists and if it does enables Formatter
             * to write encoded output to file. Catches SecurityException and
             * FileNotFoundException and prints appropriate message to user.
            if (outputFile.exists())
                try
                    output = new Formatter( new File( destination ) );
                catch ( SecurityException securityException )
                    System.err.println("You do not have write access to this file.");
                    System.exit( 1 );
                catch ( FileNotFoundException filesNotFoundException )
                    System.err.println("Error: File does not exist.");
                    System.exit( 1 );
         * Closes both input and output files after output file has been written
         * to.
         * @see #openFiles
        private void closeFiles()
            if ( output != null )
                input.close();
                output.close();
        }Edited by: fearofsoftware on Apr 17, 2009 8:35 PM

  • JNI multidimensional Array and OpenCV

    Hello everybody,
    my first post, so lets go..
    At the moment I am writing my thesis in the filed of automatic image classification. The project is written in Java, but I wanna use the OpenCV library from Intel (http://sourceforge.net/projects/opencvlibrary/) for facedetection.
    So far I managed to call the native method from Java. What I do I parse the path of the image to be analyzed as a string to my C++ programm. The faces are being detected and written into a so called CvSeq (http://www.comp.leeds.ac.uk/vision/opencv/opencvref_cxcore.htm#cxcore_ds_sequences) which holds the coordinates of the rectangles surrounding the found faces. Until now I can only call cvSeq->total which gives me the total number of faces as ints. That integer I return to my java api.
    What I don't know is, how to return a multidimensional array (2 dimensions) where the first dim contains the path as a string to the file and the second dimension 3 integers for x,y coordinates and the lenght of each rectangle.
    Or better, I might know how to return that Array, but not how to create it.
    I know this is somewht OpenCV specific, but maybe someone knows anything. Any little help would be greatly appreciated. Thanks a lot!!!!
    Regards
    Carsten
    attached: JNI source code
    /////////////////////////////////////////// source code ///////////////////////////////////////////////
    #include "cv.h"
    #include "highgui.h"
    #include "cxcore.h"
    #include "cxtypes.h"
    #include "cvaux.h"
    #include "org_kimm_media_image_data_JNIOpenCV.h"
    #include <stdio.h>
    JNIEXPORT jint JNICALL
    Java_org_kimm_media_image_data_JNIOpenCV_getFaces(JNIEnv *env, jobject object, jstring path)
    //declarations
    CvHaarClassifierCascade *pCascade = 0;
    CvMemStorage *pStorage = 0;
    CvSeq *pFaceRectSeq;
    int scale=1;
    jobjectArray recPoints;
    const char *str = env->GetStringUTFChars(path, 0);
    //initializations
    IplImage* pInpImg = cvLoadImage(str, CV_LOAD_IMAGE_COLOR);
    IplImage* small_image = pInpImg;
    pStorage = cvCreateMemStorage(0);
    pCascade = (CvHaarClassifierCascade *)cvLoad
         (("C:/OpenCV/data/haarcascades/haarcascade_frontalface_default.xml"),0, 0, 0 );
    //validaste that everything initilized properly
    if( !pInpImg || !pStorage || !pCascade)
         printf("Initialization failed: %s \n",
              (!pInpImg) ? "didn't load image file" :
              (!pCascade) ? "didn't load Haar Cascade --"
                   "make sure Path is correct" :
              "failed to allocate memory for data storage");
         exit(-1);
    //performance boost through reducing image size by factor 2          
              small_image = cvCreateImage( cvSize(pInpImg->width/2,pInpImg->height/2), IPL_DEPTH_8U, 3 );
    cvPyrDown( pInpImg, small_image, CV_GAUSSIAN_5x5 );
    scale = 2;
    //detect faces in image
    pFaceRectSeq = cvHaarDetectObjects(small_image, pCascade, pStorage,
                                            1.1,                                        //increase search scale by 10% each pass
                                            6,                                        //drop group of fewer than three detections
                                            CV_HAAR_DO_CANNY_PRUNING,          //skip regions unlikely to contain faces
                                                 cvSize(50,50));                         //use XML default for smallest search scale
    //initialize array for location of the faces (HERE IS WHERE I GET INTO TROUBLE!!!!!)
    int x = pFaceRectSeq->total;
    jclass intArrCls = env->FindClass ( "[I" ) ;
    recPoints = env->NewObjectArray ( x, intArrCls, NULL ) ;
    //for(int j = 0; j <= x; j++) {
    //   recPoints[j] = (jintArray)env->NewIntArray(3);
    for(int i=0;i<(pFaceRectSeq ? pFaceRectSeq->total:0); i++)
                                       CvRect* r = (CvRect*)cvGetSeqElem(pFaceRectSeq, i);
                                       CvPoint pt1 = {(r->x)*scale, (r->y)*scale};
                                       CvPoint pt2 = {(r->x + r->width)*scale, (r->y + r->height)*scale};
    //env->SetObjectArrayElement(recPoints,i, pt1.x);
    return pFaceRectSeq->total;
    }

    Any Java array you can consider like one-dimensional array of arrays n-1 dimension. For example, you have a 3 dim. array of objects:
    Object[][][] arr = new Object[1][2][6]; It can be considered as a set of one-dimensional arrays:
    ==========================================
    |  dim   |           Type
    ==========================================
      0          1 element, an array of type �[[Ljava/lang/Object;�
      1          1 x 2 elements , an arrays of type �[Ljava/lang/Object;�
    So you can convert three-dimensional array to one-dimensional array like in C++:
    |�[Ljava/lang/Object;� | �[Ljava/lang/Object;� | �[Ljava/lang/Object;�
         6 objects                 6 objects                 6 objects

  • Question on System.arraycopy method and multidimensional array

    I'm trying to copy from single dimensional to multidimensional array using System.arraycopy method. The following is my problem.
    1) I need to specify the index of the multidimensional array while copying. Can I do that ? If yes , how???
    eg ; int a[] = new int[3];
    int b[] = new int[3][2]; I need to copy from a to b
    I tired the following and I'm getting an error.
    System.arraycopy(a,0,b[][1],0,3);
    How Can I achieve the above?? PLease Help --------------

    Java doesn't have multidimensional arrays. When you see an int[][] it's an array of arrays of ints. The arrays of ints might have different lengths like this one:int[][] arr =
    {{1,2,3,4},
    {1,2,3},
    {1,2},
    {1}
    };Do I need to say that arraycopy as you see it would fail in this case?
    If you know what kind of arrays you'll have you can simply implement your own arraycopy method (but it will not be as effecient as System.arraycopy) with a simple for-loop.

  • Reading Java multidimensional array in C

    Hello friends.
    Have searched the forum, but haven's found the answer.
    I need to access a Java two dimensional array from C ( boolean[][] a; ).
    Here's the code in C:
      jbooleanArray aArray; 
      jboolean **a;   
      fid=(*env)->GetFieldID(env, cls, "a", "[[Z"); 
      if (fid==0) { return; }  aArray=(*env)->GetObjectField(env, jobj, fid); 
      len=(*env)->GetArrayLength(env, aArray); 
      a=(jboolean **) (*env)->GetBooleanArrayElements(env, aArray, 0);Array lengths are correctly read separately. When I debug array in C it fails half-way or so:
      for (i=0;i<arows;i++)   
        for (j=0;j<acols;j++)      
          printf("a[%d][%d]=%u ",i,j,a<i>[j]);Error: An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x189217B4
    Is it the correct way to read multidimensional array? Or could it be the problem with jboolean type?
    Kev

    Thank you for the idea to test an multidimensional array.
    I testet the following code with C++ and changed it afterwords (untestet) into the syntax of C. Hope it runs.
    boolean[][] is an array of Objects, this Objects are arrays of boolean!
    #include "nativetest_BooleanArrayTest.h"
    #include <stdio.h>
    // without "if(blabla == 0) return;" etc.
    JNIEXPORT void JNICALL Java_nativetest_BooleanArrayTest_test
      (JNIEnv * env, jobject obj)
       jsize i, j;
       jclass clazz = (*env)->GetObjectClass(env, obj);
       jfieldID fid = (*env)->GetFieldID(env, clazz, "b", "[[Z");
       jobject jobj = (*env)->GetObjectField(env, obj, fid);
       jobjectArray jarrRows = (jobjectArray)jobj;
       // Get elements of array
       jsize numberOfRows = (*env)->GetArrayLength(env, jarrRows);
       jboolean** carr = new jboolean*[numberOfRows];
       jbooleanArray* jrows = new jbooleanArray[numberOfRows];
       for (i = 0; i < numberOfRows; ++i) {
          jrows[i] = (*env)->GetObjectArrayElement(env, jarrRows, i);
          carr[i]  = (*env)->GetBooleanArrayElements(env, jrows, 0);
    jsize numberOfColumns = (*env)->GetArrayLength(env, jrows[0]);
    // test
    for (i = 0; i < numberOfRows; ++i) {
    for (j = 0; j < numberOfColumns; ++j) {
    // printf ...
    // release
    for (i = 0; i < numberOfRows; ++i) {
    (*env)->ReleaseBooleanArrayElements(env, jrows[i], carr[i], 0);
    delete[] jrows;
    delete[] carr;

  • PHP-substract array from other array

    That should be simple, yet I can't find a simple solution...
    I have two multidimensional arrays, for example:
    FIRST ARRAY:
    Array
    [0] => Array
    [0] => Ring
    [1] => 20.00
    [1] => Array
    [0] => Bracelet
    [1] => 75.00
    [2] => Array
    [0] => Bracelet
    [1] => 75.00
    and SECOND ARRAY:
    Array
    [0] => Array
    [0] => Bracelet
    [1] => 75.00
    Note that in the first array, [1] and [2] are the same, and
    in the second array, [0] is equivalent
    to both [1] and [2] in the first array.
    Basically I want to SUBSTRACT second array from first array,
    regadless of key order, that is, i want
    to remove ONE
    [0] => Bracelet
    [1] => 75.00
    from first array.
    So that the resulting array will be:
    Array
    [0] => Array
    [0] => Ring
    [1] => 20.00
    [1] => Array
    [0] => Bracelet
    [1] => 75.00
    I have looked the array functions at php.net, but I have not
    seen a function that does that, or did
    not realize i saw it if i did.
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    An Ingenious WebSite Builder:
    http://sitelander.com

    ok i did what i wanted it with a foreach loop and a little
    trickery...
    still curious to know if there is a one-line ready-made php
    function for that though...
    (_seb_) wrote:
    > That should be simple, yet I can't find a simple
    solution...
    >
    > I have two multidimensional arrays, for example:
    >
    > FIRST ARRAY:
    > Array
    > (
    > [0] => Array
    > (
    > [0] => Ring
    > [1] => 20.00
    > )
    >
    > [1] => Array
    > (
    > [0] => Bracelet
    > [1] => 75.00
    > )
    > [2] => Array
    > (
    > [0] => Bracelet
    > [1] => 75.00
    > )
    > )
    >
    > and SECOND ARRAY:
    > Array
    > (
    > [0] => Array
    > (
    > [0] => Bracelet
    > [1] => 75.00
    > )
    >
    > )
    >
    > Note that in the first array, [1] and [2] are the same,
    and in the
    > second array, [0] is equivalent to both [1] and [2] in
    the first array.
    >
    > Basically I want to SUBSTRACT second array from first
    array, regadless
    > of key order, that is, i want to remove ONE
    >
    > [0] => Bracelet
    > [1] => 75.00
    >
    > from first array.
    >
    > So that the resulting array will be:
    >
    > Array
    > (
    > [0] => Array
    > (
    > [0] => Ring
    > [1] => 20.00
    > )
    >
    > [1] => Array
    > (
    > [0] => Bracelet
    > [1] => 75.00
    > )
    > )
    >
    > I have looked the array functions at php.net, but I have
    not seen a
    > function that does that, or did not realize i saw it if
    i did.
    >
    seb ( [email protected])
    http://webtrans1.com | high-end web
    design
    An Ingenious WebSite Builder:
    http://sitelander.com

  • Working with MultiDimensional arrays

    Hi,
    Just wondering if anyone could help with a problem Im
    having with multi-dimensional arrays in Java:-
    I want to create a multi-dimensional array (e.g. 3 dimensions). I know this can be defined by code such as:-
    int[ ][ ][ ] my_array = new int[10][10][10];
    (would create a 10x10x10)
    My problem is that I want to address the array with indexes that aren't known at compile time, trying to do this causes an error:-
    e.g. my_array[0][0][0] = 1; is ok (i.e. the element at 0,0,0 is set to 1)
    but if the indexes 0,0,0 are replaced by the return value of some function,
    e.g.
    my_index1 = generateIndex(x, y, .... etc);
    my_index2 = generateIndex(a, b, ...etc);
    my_index3 = generateIndex(f,g, .. etc);
    (where generateIndex is some function that returns an integer)
    and the array element set with
    my_array[my_index1][my_index2][my_index3] = 3;
    This generates an error. I know that this problem can be overcome through the use of pointers in C++ but since Java doesn't use pointers, im a bit stuck!
    I have come across a method that overcomes this for a 1D array, using the setInt function of the Array class, e.g.
    Array.setInt(my_1Darray, 0, 1); (would set the first value of my_1Darray to 1);
    (i.e. Array.setInt(array_name, int index, int value);
    But I can't see how this works with multidimensional arrays.
    If anyone could shed any light on this problem, that would be great.
    Thanks,
    Peter

    public class NDArray {
            public static void main(String[] s) {
                    int[][][] _3D = new int[10][10][10];
                    for (int c = 0; c < 1000; c++)
                            _3D[rnd()][rnd()][rnd()]=rnd();
                    for (int i=0; i < 10; i++) {
                      for (int j=0; j < 10; j++) {
                        for (int k=0; k < 10; k++) {
                            System.out.print(_3D[i][j][k]);
                            System.out.print(" ");
                      System.out.println();
                    System.out.println();
            static int rnd() {return (int) (10*Math.random());}
    /* output (example):
    7 0 0 4 9 9 3 0 0 2
    0 1 8 9 6 0 0 0 0 0
    5 3 0 5 0 0 1 0 0 3
    5 6 0 5 0 0 3 0 0 0
    0 0 0 0 4 0 0 5 8 6
    0 9 0 9 0 1 0 2 0 0
    3 3 8 6 0 0 1 0 3 4
    9 6 7 0 0 0 3 6 6 3
    2 0 8 7 0 1 4 0 7 0
    8 0 4 4 3 0 0 5 4 0
    0 0 0 0 3 0 1 0 0 4
    9 0 8 9 1 0 9 0 9 0
    0 8 3 4 1 0 8 0 0 2
    3 0 0 7 3 3 0 5 0 0
    0 0 0 1 4 6 0 0 0 3
    3 5 8 5 8 0 8 2 0 4
    4 0 1 7 0 1 0 4 4 0
    6 0 5 0 0 4 0 8 1 0
    0 0 6 6 2 0 0 4 5 0
    0 6 7 0 4 0 7 5 0 0
    2 4 0 5 0 0 0 2 1 7
    0 6 0 9 0 0 6 1 2 0
    0 5 9 0 1 2 4 0 8 6
    0 0 8 0 0 3 3 8 0 0
    4 7 5 9 0 8 1 0 0 9
    2 0 0 3 0 0 8 3 0 7
    0 6 0 6 0 0 0 0 1 0
    0 9 9 8 4 2 0 0 7 2
    4 0 0 9 0 0 0 1 0 6
    7 0 6 5 2 3 7 8 0 2
    0 0 3 5 0 0 0 0 0 0
    3 0 0 0 0 2 0 0 6 0
    6 0 3 3 6 0 4 0 1 6
    0 0 7 2 0 8 0 0 0 0
    0 0 9 0 6 8 2 1 0 0
    9 0 4 1 3 9 3 2 7 7
    0 3 1 0 3 0 0 9 0 5
    0 0 0 0 6 0 4 8 0 5
    1 8 4 6 7 0 0 4 4 0
    0 4 8 0 0 0 6 0 4 0
    0 9 3 0 0 0 6 0 0 8
    6 8 2 9 6 0 0 7 9 0
    7 1 9 0 0 5 0 2 3 0
    0 0 0 0 9 9 0 7 0 9
    9 8 8 2 9 8 0 5 8 0
    2 3 0 4 0 4 1 0 6 9
    3 3 0 0 0 0 7 6 9 3
    6 2 2 1 0 5 8 3 0 6
    0 6 0 0 0 0 0 0 7 5
    0 6 0 0 0 3 3 0 2 0
    3 6 5 5 8 2 0 9 1 0
    8 0 7 0 9 0 9 0 2 0
    0 2 9 0 0 1 2 4 0 2
    3 1 0 2 0 0 0 0 0 0
    0 5 0 3 8 8 3 0 0 0
    9 0 9 0 5 1 0 9 5 0
    8 0 0 8 8 7 0 3 1 0
    4 0 0 0 1 8 0 9 0 5
    0 0 6 6 0 0 5 2 6 8
    0 4 0 9 0 0 2 0 0 3
    0 5 8 1 7 0 0 4 2 0
    6 5 0 0 2 0 6 8 8 7
    0 0 0 0 3 0 8 4 0 0
    2 3 3 0 0 7 6 8 0 4
    4 1 7 3 8 0 2 3 3 0
    1 5 0 0 4 1 3 7 3 1
    0 0 0 6 0 6 0 0 3 0
    3 7 0 4 5 9 5 5 0 8
    3 8 6 4 0 0 0 1 6 0
    0 0 2 0 2 9 0 0 0 5
    0 5 6 0 5 5 4 0 6 7
    0 2 2 0 9 7 4 2 9 0
    4 0 5 4 8 3 0 0 2 0
    0 0 9 3 3 0 8 8 7 0
    0 7 9 7 0 0 0 7 1 0
    2 0 0 0 5 8 2 0 0 5
    2 4 9 6 6 0 0 0 6 0
    0 6 6 7 0 2 0 0 5 2
    0 9 0 4 8 5 1 0 7 6
    0 0 7 0 4 0 3 8 0 9
    9 4 0 0 0 4 0 0 0 5
    2 0 4 7 7 5 4 0 9 0
    0 0 1 0 5 0 1 0 6 0
    0 6 0 9 0 9 0 4 7 0
    5 9 6 6 2 8 8 4 1 4
    9 7 3 2 7 6 0 2 3 0
    3 1 5 0 8 0 0 0 0 0
    9 0 0 3 0 8 7 0 4 0
    8 6 6 4 0 4 6 4 5 0
    0 0 0 0 0 4 4 0 0 9
    8 8 0 2 0 0 0 1 0 0
    6 2 1 1 9 0 5 1 0 0
    0 9 1 0 6 0 4 0 0 0
    9 4 0 3 0 1 0 7 6 0
    0 9 0 7 8 6 0 5 0 0
    0 8 8 9 0 5 7 0 0 0
    0 4 5 1 6 0 5 2 9 3
    6 0 0 0 0 0 0 9 1 0
    5 9 1 9 2 5 3 0 0 9
    2 9 5 1 7 0 0 0 9 0
    */Seems to work just fine. How is your code different from mine?

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • How do I remove NaN values from an array?

    I'm trying to test if the values in an array are less than 0.001. All of them are...BUT the problem is that some of the elements in the array are NaN. I'd like to do one of two things:
    1. Remove the NaN elements from the array and set them to zero to make the test work.
    2. Make the test understand that NaN elements are okay.
    The test results in a boolean array of T/F values. If all of the values of the boolean array are T, it will result in a single boolean value of T. In #2, I am saying that I want it to test if an element of the array is less than 0.001 OR equal to NAN.
    Solved!
    Go to Solution.

    Your statements don't make much sense. It's irrelevant how many NaNs are in the array. A sort will move them all to the bottom. You had said you wanted to find out if all the elements in an array are less than 0.001, and that you've got some NaNs in there. Well, this will do that:
    twolfe13 wrote:
     I did see how to remove NaN once, but couldn't determine a good way to generalize it other than doing a test loop. I thought there might have been a simple function that I overlooked to do this.
    As I noted, there have been several posts in the past about efficient techniques for removing certain elements out of an array. Seek, and ye shall find.
    Joseph Loo wrote:
    Have you look at the coerce function where you can set the lower and upper limit?
    That won't do anything for NaN. Or perhaps I misunderstood what you are suggesting to do?
    Attachments:
    NaN sort.png ‏20 KB
    NaN sort small.png ‏5 KB

  • Without loops how can i read data from associative Array??

    Hi all,
    I am facing scenario like...
    i need to read data from associative array  without using loops is it possible,
    CREATE OR REPLACE PACKAGE BODY test_pkg IS
        TYPE t1 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       -- in array we can expect more than one row or sometimes no data also.
      FUNCTION test1(vt1 T1 DEFAULT CAST(NULL AS t1)) RETURN NUMBER IS
      BEGIN
        -- basically in array we'll get data of column2
        -- this loop should satisfies table1.colum2 = nvl(NULL, table2.colum2 )if array is null.
        -- if array is not null then only compare with array values
        FOR i IN (SELECT t1.colum1,t1.column2
                         FROM table1 t1, table1 t2
                              WHERE t1.colum1 = t2.column1
                                AND t1.colum2 = nvl(vt1, t2.colum2)
          LOOP
            generateTEXT(i.colum1, i.colum2);
         END LOOP;
      END test1;
    END test_pkg;
    in table1 we have date like...
    colum1          column2
    Jan                  1
    Feb                  2
    Mar                  3
    if i call select test_pkg.test1(1) from dual then output should
    be Jan..
    and
    select test_pkg.test1(null) from dual then it should display all elements from table1.
    Jan                  1
    Feb                  2
    Mar                  3,
    Thanks for your quick replay..

    i need to read data from associative array  without using loops is it possible,
    No - you would need to create a SQL type and then use the TABLE operator to unnest the collection.
    create or replace TYPE my_nums IS TABLE OF INTEGER;
    DECLARE
    --  TYPE my_nums IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
      v_nums my_nums := my_nums(1, 2, 3);
      v_total number;
    BEGIN
      select sum(column_value) into v_total from table(v_nums);
      DBMS_OUTPUT.PUT_LINE
        ('Sum of the numbers is ' || TO_CHAR(v_total));
    END;
    Sum of the numbers is 6

  • How to delete rows from 2D array in this case...

    Hello. I'm just begging adventure with labview so please for patient. I created a program whitch suppose work in following way:
    2D Input array is array created by FOLDER BROWSING subVI. It works in this way,that browse folder and looking for txt files whose contanins measurment data. In my case subVI founds 4 files,and from theirs headers read information about what kind of data are in file also their's path. In this way is created 2D Input Array. subVI named PLOTS FROM PATHS ARRAY make picture with polar/XY plot. It's create only those plots and legends on one picture as many files(their paths) is setted to the program by output array. I made this subVI in that way and I would not like to change it. 
    My problem is that in even loop (witch check for any change by user) program suppose to relay anly those rows(files) for which checkbox are marked, e.g. marking anly 1 and 4 box, program should chose from input array row 1 and 4 only and pass them to output array,then  PLOTS FROM PATHS ARRAY subVI makes a picture only with 1 and 4 plot and legend only for plot 1 and 4. The best solution would be some relay witch is avtivated by logical signal. It lost to me ideas how to solve it, I'm just in blaind corner...
    I tried to use delete from array but I don't know how to do use it properly in this program,becease it can be only before or afeter for loop. Below is scan of front panel and also main problem. Please set me up somehow to solve this problem. 
    Regards 
    Solved!
    Go to Solution.
    Attachments:
    plots selector.vi ‏17 KB
    problem.PNG ‏18 KB

    I have attached a vi. Is this the one that you need?
    Anand kumar SP
    Senior Project Engineer
    Soliton Technologies Pvt Ltd
    Attachments:
    plot selector modified.vi ‏14 KB

Maybe you are looking for

  • ConnectionManager::invoke::Failed to find service connection url.

    Please fix this Apple, I can't sign in or make purchases. I have tried the following... Delete cache.db Restart iMac Default security settings Firewall is off Little Snitch is not installed Thanks

  • Problem with file transfer

    When i try to transfer a non zipped file or a pages file i've got this error, it's recent but can't tell you when. But I can transfer image (jpg, png...) I've Chax version 1.4.8 for Mac OS X 10.4.3. Impossible d'envoyer le fichier "Sans titre.pages"

  • Content Search in CMDSK

    Hi guys, What is required for all new files to be indexes (the content). Oracle Text is installed and all that.. i can do context search but no results are returned. It is not enabled automatically or do I have to specify a command to index the conte

  • Firefox does not inherit GTK+ font settings

    The Nvidia drivers for the GTX 660ti gpu seem to be breaking the font rendering in Firefox' UI. I doubt this issue can be resolved here but in the meantime if anyone is experiencing the same problems their input would be valuable. Last edited by Raps

  • All sms have been deleted on N97. Can i get them b...

    How do you backup text messages (SMS) to prevent this in the future?  All my 569 sms have now been deleted when I switched off the phone and turned it on again. What a **bleep** telephone!!!