Problem in assigning values to 2-dimensional arrays...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumuka
    New Member
    • Oct 2007
    • 38

    Problem in assigning values to 2-dimensional arrays...

    Hello,

    I'm doing a project in java and im not able to assign the values which are got from for loop to the 2-dimensional array.
    Can anyone tell me how to assign the values and print them?

    the code is:
    Code:
                               gr.getGridArray();
    	           for (int s=0;s<=NoOfElevations;s++)
    	        	   for (int t=0;t<=NoOfElevations;t++)
    	        	   {
    	                        temp[][] = ;
    	                        System.out.println("values are " + temp[s][t]);
    	        	   }
    	       }
    How will i assign s and t values to temp array?

    Thanks in anticipation... ....
  • dav3
    New Member
    • Nov 2006
    • 94

    #2
    Originally posted by sumuka
    Hello,

    I'm doing a project in java and im not able to assign the values which are got from for loop to the 2-dimensional array.
    Can anyone tell me how to assign the values and print them?

    the code is:
    Code:
                               gr.getGridArray();
    	           for (int s=0;s<=NoOfElevations;s++)
    	        	   for (int t=0;t<=NoOfElevations;t++)
    	        	   {
    	                        temp[][] = ;
    	                        System.out.println("values are " + temp[s][t]);
    	        	   }
    	       }
    How will i assign s and t values to temp array?

    Thanks in anticipation... ....
    I havnt worked with 2d arrays much but line 5 looks like it has a problem.

    Comment

    • heat84
      New Member
      • Nov 2007
      • 118

      #3
      Originally posted by sumuka
      Hello,

      I'm doing a project in java and im not able to assign the values which are got from for loop to the 2-dimensional array.
      Can anyone tell me how to assign the values and print them?

      the code is:
      Code:
                                 gr.getGridArray();
      	           for (int s=0;s<=NoOfElevations;s++)
      	        	   for (int t=0;t<=NoOfElevations;t++)
      	        	   {
      	                        temp[s][t] =someValue ;
      	                        System.out.println("values are " + temp[s][t]);
      	        	   }
      	       }
      How will i assign s and t values to temp array?

      Thanks in anticipation... ....
      You assign someValue to the array at [s][t] . Is your problem solved?

      Comment

      • sumuka
        New Member
        • Oct 2007
        • 38

        #4
        Originally posted by heat84
        You assign someValue to the array at [s][t] . Is your problem solved?
        Thanks for replying .
        But i need to assign the values of s and t which i've used in the for loop .
        I need to assign the values of s and t to this array and then display.

        Please help....

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by sumuka
          Thanks for replying .
          But i need to assign the values of s and t which i've used in the for loop .
          I need to assign the values of s and t to this array and then display.

          Please help....
          Variables s and t are *two* values; a single cell in a two dimensional array can
          just contain *one* single value.

          kind regards,

          Jos

          Comment

          • samido
            New Member
            • Oct 2007
            • 52

            #6
            Originally posted by sumuka
            Thanks for replying .
            But i need to assign the values of s and t which i've used in the for loop .
            I need to assign the values of s and t to this array and then display.

            Please help....
            dude, s&t are not the values of the array but index's, two dimentional array has pair of number to form a specific index of theh array value, for example arr[1][0] is the value at second horizontal line but first in the vertical line of you dimenssions, do you want the index(position) of the value or do you want the value? ...

            Comment

            • heat84
              New Member
              • Nov 2007
              • 118

              #7
              Originally posted by sumuka
              Thanks for replying .
              But i need to assign the values of s and t which i've used in the for loop .
              I need to assign the values of s and t to this array and then display.

              Please help....
              Ok , you can create an object e.g MyValues that that contains the s and t as instance variables.
              for example
              Code:
               
                 1.
                    gr.getGridArray();
                 2.
                                   for (int s=0;s<=NoOfElevations;s++)
                 3.
                                       for (int t=0;t<=NoOfElevations;t++)
                 4.
                                       {
                                  MyValues someValue=new MyValues(s,t);
                 5.
                                                temp[s][t] =someValue ;
                 6.
                                                System.out.println("values are " + temp[s][t]);
                 7.
                                       }
                 8.
                               }
              In this case the tempArray then will have to be of MyValues type.

              Hope this is helpful.....

              Comment

              Working...