그래서 나는 자바 초보자입니다. 배열의 정수가 나에게 알려주는 프로그램을 만들려고합니다. 그러나, 나는 경계 오류에서 배열을 점점 계속 : 10 내가 "[도 [] B] 공식을 SY 29 행 (에 제발 도와주세요배열 범위 밖 예외 오류 자바
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