please can someone help and correct this i got a problem trying to create 2 dime
ID: 3637420 • Letter: P
Question
please can someone help and correct this i got a problem trying to create 2 dimensional 16x16 arraycode below:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arrays;
/**
*
* @author fishaq
*/
public class Map {
int Position;
int[][] Grid = new int [16][16];
// ALL DATA FIELDS ARE SET
// position get and set below
public void setPosition(int newPositionValue)
{
Position = newPositionValue;
}
public int getPosition()
{
return Position;
}
// GET AND SET INT GRID
public void setGrid(int [][] newGridValue)
{
Grid = newGridValue;
}
public int [][] getGrid()
{
return Grid;
}
public void get()
{cout<<"enter elements in 16*16 grid";
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
{
cin>>Grid[i][j];
}
cout<<" enter position";
cin>>position;
}
void set()
{
int row=position/16;
int column=position%16;
cout<<"the elements at postion"<<position<<"is ";
cout<<Grid[row][column];
}
};
int main()
{
map DataEntry;
DataEntry.get();
DataEntry.set();
return 0;
}
Explanation / Answer
I think you need to specify the number of columns . int[][16] Grid = new int [16]...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.