- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at cohttp://m.day5.Test1.main(Test1.java:26)
for(int i=0;i<=num.length;i++) {// i< num.length(배열개수)으로 바꾸어야한다.
→배열에서 인덱스는 사람이 생각하는 n-1이다.
- Exception in thread "main" java.lang.Error: Unresolved compilation problems:
i cannot be resolved to a variable
i cannot be resolved to a variable
i cannot be resolved to a variable
i cannot be resolved to a variable
at com.day5_ex1.Test1.main(Test1.java:15)
▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
public static void main(String[] args) {
//선언
Scanner sc= new Scanner(System.in);
int[] num= new int[5];
//입력
System.out.println("5개 숫자 입력?");
for(i=0; i<num.length;i++) { //int 선언부 없음 오류 int
num[i] =sc.nextInt();
}/*->for(i=0; i<num.length;i++) { //int 선언부 없음 오류 int
num[i] =sc.nextInt();
} 으로 수정하여 해결완*/
//공백지정(숫자 안밀리게 하기)
for(i=0; i<week;i++) {
System.out.println(" ");// println 이 아니라 print() 써야 안밀림
}
→해결
- Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error, insert ". class" to complete Expression
The type of the expression must be an array type but it resolved to Class<Integer>
at com.day5_ex1.Test5.main(Test5.java:14)
오류
Scanner sc= new Scanner(System.in);
int i,j,temp;
int num[]= int[5];
System.out.println("숫자 입력 5개?");
for (i=0;i<num.length;i++ ) {
num[i]= sc.nextInt();
}
해결
Scanner sc= new Scanner(System.in);
int i,j,temp;
int num[]= new int[5];//// 새로 배열 만들때는 new!!!
System.out.println("숫자 입력 5개?");
for (i=0;i<num.length;i++ ) {
num[i]= sc.nextInt();
}
System.out.print("Sorce Data");
for(i=0; i<num.length;i++) {
System.out.printf("%4d",num[i]);
}
System.out.println();
//연산부
//selection sort
for(i=0; i<num.length-1;i++) {
for(j=0;j<num.length;j++) {// j=i+1;
if(num[i]>num[j]) {
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
'【♣부트 캠프♣】 > ▷부캠- 에러 모음' 카테고리의 다른 글
[24.05.27-7일차] (0) | 2024.05.27 |
---|---|
[24.05.24-6일차] (0) | 2024.05.24 |
[24.05.22] (0) | 2024.05.22 |
[24.05.21] 코드리뷰+에러모음 선언부를 입력 잘 못함 (0) | 2024.05.22 |
[24.05.21] (0) | 2024.05.21 |