尝试设计一个读取整数并打印 2 和输入值之间的所有偶数整数之和的应用程序。有人可以帮我做最后一点吗?!
import java.util.Scanner;
public class IntegerValue {
// main method
public static void main(String[] args) {
// Data fields
int a;
// end
Scanner sc = new Scanner(System.in);
System.out.println("Enter an integer greater than 1");
a = sc.nextInt();
if (a <= 1) {
System.out.println("Input Value must not be less than 2");
}
while (a > 1) {
int sum = 0;
if (a % 2 == 0) {
sum += a;
a = a - 1;
}
System.out.println(sum);
}
}
}