为什么我的循环出不来了?总是停不了?

我想定义一个输入6个数字生成一个数组的方法,但是每次循环完了就会重新循环,永远出不来,是哪里出错了?
public static int[] getScore() {
int[] score = new int[6];
Scanner sc = new Scanner(System.in);
for(int i=0;i
System.out.println("please input"+" "+(i+1)+"th"+" "+"number");
int num = sc.nextInt();
if(num<=100&&num>+0) {
score[i] = num;
i++;
}else {
System.out.println("error");
}
}
return score;
}

运行结果为:
please input 1th number
11
please input 2th number
11
please input 3th number
22
please input 4th number
34
please input 5th number
55
please input 6th number
66
(到这里应该运行完的,可以又重新开始循环第一次的了)
please input 1th number

好像没问题。测试代码如下:

import java.util.Scanner;

public class ScoresTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        getScore();
    }
    
    public static int[] getScore() {
        int[] score = new int[6];
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<score.length; ) {
            
            System.out.println("please input"+" "+(i+1)+"th"+" "+"number");
            int num = sc.nextInt();
            if(num<=100&&num>+0) {
                score[i] = num;
                i++;
            }else {
                System.out.println("error");
            }
        }
        return score;
    }

}


img

是不是调用这个getScore()函数的代码重复调用这个函数了啊。这个函数本身不可能有这种效果的

检查一下,你是不是循环调用了这个方法getScore(),搜索一下

函数本身没有问题,你是怎么调用的,代码呢
你是不是把getScore本身放进while循环里了


public static int[] getScore() {
int[] score = new int[6];
Scanner sc = new Scanner(System.in);
for(int i=0;i<score.length;i++) {
System.out.println("please input"+" "+(i+1)+"th"+" "+"number");
int num = sc.nextInt();
if(num<=100&&num>+0) {
score[i] = num;
}else {
System.out.println("error");
}
}
return score;
}