java for语句递减,for循环递减2到0并总结在得到0之前生成的值

我试图找到一种方法从用户输入的int倒计数,然后添加每个秒值,因为我倒数到0

例如 .

{用户输入10

计划倒计时8,6,4,2,0

然后加10 8 6 4 2 0 = 30

}

我怎么能使用嵌套的for循环来做到这一点

到目前为止,我只能接受用户输入,每次倒数2 . 我到0但没有办法增加每一个值 . 我的代码:

到目前为止,它只计为0

public class Week5b {static Scanner userVal = new Scanner(System.in);

public static void main(String[] args) {

//printTable();

reverseAddSkip();

public static void reverseAddSkip(){

System.out.println("Please enter an integer");

for (int i = userVal.nextInt(); i >=0; i-=2){

System.out.println(i) ;

}/* this creates a loop where the variable i is equal to user input;

the condition for the loop to continue is whether the input is larger or equal to 0; the update part of the loop takes 2 away each time, as if it were -- (which takes away one each time) */

}

我怎样才能用数学方法写出来?将i- = 2的总和加到i的原始值 . 你键入11,它计数9 7 5 3 1,然后加上11 9 7 5 3 1.并给你总和 .

不知道如何从用户值中减去每2个减2的数字 .

你输入50,它倒数2到0你把51倒计数2到0但我还没有发现总和所有那些在得到0之前生成的数字:/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值