如,输入7,程序进行7-6-4-2,输出-5
谢谢谢谢!
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int i;
if(n<=0){
System.out.println("请输入正整数!");
}else{
if(n%2==0){//n是偶数
i = n;
}else{//n是奇数
i = n-1;
}
while(i>0){
n = n-i;
i = i-2;
}
System.out.println(n);
}
}
}