在while判断x之前先获得一个x值:
import java.util.Scanner;
public class Test40008 {
public static void main(String args[]) {
int ri, repeat;
int x = 0, sum;
Scanner in = new Scanner(System.in);
/*---注释掉没用的
repeat = in.nextInt();
for (ri = 1; ri <= repeat; ri++)
x = in.nextInt();
---*/
sum = 0;
x = in.nextInt();/////////////////
while (x > 0) {
if (x % 2 == 1)
sum = sum + x;
x = in.nextInt();
}
System.out.println(sum);
}
}