z13428206339 @ 2023-03-02 01:53:59
import java.util.Scanner;
/**
* @Author:
* @Date: 2023/3/2 1:04
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int k = scanner.nextInt(); //表示发放金币的天数
int jb = 0; //总金币数
int count = 1; //要发金币数
for (int i = 0; i <= k ; i++) {
k = k - count; //1 22 333
for (int j = 0; j <= i ; j++) {
jb = jb + count;
}
count++;
}
System.out.println(jb);
}
}
by linmaozi @ 2023-03-30 22:19:50
错误:判断循环结束的时机不对,你这个只能当内循环结束,才判断结束条件。 提醒:发放金币的天数也就是增加金币的次数。