数字累加

来源:互联网 发布:郑州网络推广公司 编辑:程序博客网 时间:2024/06/11 05:54
public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int start = sc.nextInt();//开始的累加的数字        int end = sc.nextInt();//累加结束的数字        int i = start;        int sum = 0;//累加的和        while(i <= end){//循环累加            sum += start;            start++;            i++;        }        System.out.println(sum);        sc.close();    }

运行结果:
这里写图片描述

原创粉丝点击