私は疑問を持っています。手動で導入した数値の乗算表となる次のコードを開発しています。私が得られないのは、テーブルを印刷することです。私の知る限り、すべてのコードは正しく書かれているため、何が起こっているのかわかりません。
public class Tabla
{
public static void main (String[] args)
{
int n=4;
Tabla table = new Tabla ();
int dato [];
dato=table.producto(n);
for (int j=1;j<=10;j++)
{System.out.println(dato[j]);}
}
public int [] producto(int num)
{
int a[]={'0'};
for (int i=1;i<=10;i++)
{a[i]=num*i;}
return a;
}
}
何か案は??
前もって感謝します!
**コードを次のように変更しました:
public class Tabla
{
public static void main (String[] args)
{
int n=4;
int j;
Tabla table = new Tabla ();
int dato[]=new int [10];
dato=table.producto(n);
for (j=0;j<10;j++)
{System.out.println(dato[j]);
}
}
public int [] producto(int num)
{
// make a 10-element array
int a[] = new int[10];
// fill up the array with products
for (int i = 0; i < 10; i++)
{a[i] = num * (i+1); }
return a;
}
}
魔法のように動作します!forサイクルがあったときにコンパイラが「ArrayIndexOutOfBoundsException」をスローした理由を疑問に思っています for (int i = 1; i <=10; i++)
助けてくれてありがとう!:D