我首先要获得2个输入作为第一和第二参数。然后显示这些参数之间的所有奇数。 即使我导入了java util:
,这也是我得到的输出import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
Scanner ask = new Scanner(System.in);
System.out.print("first");
int a = ask.nextInt();
System.out.print("second");
int b = ask.nextInt();
int sum = 0;
for (int n = a; n <= b; n++) {
if (n % 2 == 1) {
sum = sum + n;
System.out.print(n + " ");
}
}
System.out.print("*" + sum);
}
}
<div class="col-xl-11 col-xl-offset-1 col-lg-11 col-lg-offset-1 col-md-11 col-md-offset-1 col-sm-11 col-sm-offset-1 col-xs-11 col-xs-offset-1">