私はjavaの初心者です。配列の偶数intを示すプログラムを作成しようとしています。しかし、私は、境界エラーのうちの配列を得続ける:10私は、「[さえ[] B]式をSYライン29(で助けてください配列外の例外エラーjava
public class arrayone
{
public static void main(String args [])
{
/*
tell me the number of even ints in the given array. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1.
*/
//declare an array
int[] even= new int[10];
//int b is for the forloop so that every number can be added
int b;
//
//initialize the scanner, and enter prompt
Scanner input= new Scanner(System.in);
//enter prompt
System.out.printf("Enter 10 random numbers\n");
//make a forloop so every number they put in will be added to the array
for(b=0;b<10;b++)
{
even[b]=input.nextInt();
}
//then run the formula
formula(even[b]);
}
public static void formula(int a)
{
//use an if statement to see if the numbers in the array are odd or even.
for(a=0;a<=10;a++)
{
if((a%2)==0)
{
System.out.printf("This number is even\n");
}
else
{
System.out.printf("This number isn't even\n");
}
}
}
}
formula' '内でのすべての' for'ループがあってはなりません。あなただけが 'int'を期待しています – Aidin
私はあなたがしていると思うところで正直に迷っています。あなたの 'formula'は全く意味がありません – Aidin
各整数を式に送るのではなく、単に配列全体を送信するのではないのですか? https://repl.it/Eu6c/1 – shash678