- class Dome1 {
- public static void main(String[] args) {
- int m = getSub(1000);
- System.out.println(m);
- }
- public static int getSub(int n) {
- int even = 0;
- int odd = 0;
- for (int i = 0; i <= n; i++) {
- if (i%2 == 0) {
- even += i;
- } else {
- odd += i;
- }
- }
- return even-odd;
- }
- }
复制代码 给你修改后的代码,返回值位置不对,还有一点就是你的代码太丑了,复制饭后黏贴各种少大括号,
|