我正在解决codechef的INTEST(https://www.codechef.com/problems/INTEST),这是到目前为止的代码:

 //to scan input
import java.util.Scanner;

class Intest {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);

        int lines, divisor, counter;
        int temporary;

        //get input for problem
        lines = keyboard.nextInt();
        divisor = keyboard.nextInt();

        for (int i = 0; i < lines; i++) {
            temporary = keyboard.nextInt();
            if (temporary % divisor == 0) {
                counter++;
            }
        }
        //displays how many ints are divisible by the divisor
        System.out.println(counter);
    }
}


我应该在本地声明“临时”吗?

最佳答案

您不必在temporary循环外使用for,因此可以将其设置为for的本地内容,而无需对行为进行任何更改。

07-26 08:41