0
Multi-dimensional Array Cannot convert int to int[]?
As the title says, I keep getting an error saying I cannot convert int to int[]... what does this mean, and what do I have wrong? package practiceClasses; public class SodokuNotGame { public static void main(String[] args) { int[][][] sample = {1,2,3},{4,5,6},{7,8,9}; } }
9 Respostas
0
int [] sample={1,2,3,4,5,6,7,8,9}
//You mean like this?
0
@Atul I want it to have an array like this:
1 2 3
4 5 6
7 8 9
So 3x3, 3 rows, and 3 columns
0
class Program
{
public static void main(String[] args)
{
int count=0;
int[] arr={1,2,3,4,5,6,7,8,9};
for(int i=0;i<arr.length;i++)
{
if(count ==2)
{
count=0;
System.out.println (arr[i]);
}
else
{
count++;
System.out.print (arr[i]+" ");
}
}
}
}
0
@Atul So then what is the point of arrays like this: int [][] array = { {1,2,3},{4,5,6} }
0
int[][][] is 3d array, you need 2d
int[][] sample = {{1,2,3},{4,5,6},{7,8,9}};
0
zemiak Can you explain the difference in an array[] and array[][]
0
William Davis array[] is a 1d array. Whereas array[][] is a 2d array. And array[][][] is a 3d array
0
//import java.util.Arrays;
//here are three simple arrays of numbers
int[] arr1 = {1,2,3};
int[] arr2 = {4,5,6};
int[] arr3 = {7,8,9};
//this is array where element is another array
int[][] arr2D = {arr1, arr2, arr3};
//similar here
int[][] arr2Dx = {{1,2,3}, {4,5,6}, {7,8,9}};
//you can use it for table structure
//with row and columns, or for matrix
String s1D = Arrays.toString(arr1);
String s2D = Arrays.deepToString(arr2D);
String s2Dx =Arrays.deepToString(arr2Dx);
System.out.println(s1D);
System.out.println(s2D);
System.out.println(s2Dx);
0
zemiak Uncomment import java.util