如何使for循环扫描仪代码下降一定数量?例如,输入 30,然后输入 3,然后它会像 30、27、24、21 等一样下降。
这就是我到目前为止所拥有的。我希望 int y 表示一次删除了多少。
import java.util.Scanner; // ...
public class b
{
public static void main(String[] args) {
int x,y;
Scanner scannerObject = new Scanner(System.in);
System.out.println("how many bottles hanging on the wall");
x = scannerObject.nextInt();
System.out.println("how many bottles are taken down the wall");
y = scannerObject.nextInt();
for (int counter = x; counter > 0; counter--)
{
if (counter == 1)
{
System.out.println(" " + counter + " bottle hanging on the wall");
}
else
{
System.out.println(" " + counter + " bottles hanging on the wall");
}
System.out.println("And if one bottle should accidently fall, ");
}
System.out.println("No bottles hanging on the wall");
}
}