배열에 실제로 저장하려면 어떻게해야합니까? 이 배열 당신이 그것을 어떻게하고 자세히 설명하는 나에게 더 많은 방법을 말할 수 있기를 바랍니다 아무것도 저장하지 않습니다이 코드 , 당신에게 당신은 i
일에 값을 저장Java 배열 배열에 저장하는 방법
import java.util.Scanner;
public class CountArray
{
public static void main(String[] arg)
{
Scanner scan = new Scanner(System.in);
int countPOZ = 0;
int countP5 = 0;
int countNONE = 0;
System.out.println();
System.out.print("Type elements: ");
int[] x = new int [scan.nextInt()];
for(int i = 0; i < x.length; i++)
{
System.out.print("Type numbers: ");
int numrat = scan.nextInt();
if(numrat > 0)
countPOZ++;
else if (numrat % 5 == 0)
countP5++;
else
countNONE++;
}
System.out.println();
System.out.println(x[1]); //here it will display 0 because nothing is saved.. in the array
System.out.println("Positive: "+countPOZ);
System.out.println("Div.. with 5: "+countP5);
System.out.println("Others: "+countNONE);
}
}
감사합니다. 자세히 설명해 주시겠습니까? – user1873251
@ user1873251 관련 JLS를 추가했습니다. –
나는 개념을 알고 있지만, 나는 왜 내가 배열 [...]에 있는지 이해하는데 문제가 있다는 것을 알고있다. 나는 단지 값을 1로 계산하고 .. 2 .. .. 입력 된 요소의 수까지 .. – user1873251