0
配列で偶数を取り出したい
偶数を出力しようと思い以下のコードを書いたのですが出力されるのが奇数でした。偶数を出力するにはどうしたら良いでしょうか
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
int[] hairetsu = {1,2,3,4,5,6,7,8,9,10};
for(int i = 0; i < hairetsu.length; i++) {
if(i % 2 == 0) {
System.out.println(hairetsu[i]);
}
}
}
}