题解 | #牛牛学数列#
牛牛学数列
http://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int length = scanner.nextInt(); int target = 0; for(int index = 1; index <= length; index++){ target += (index & 1) == 1 ? index : -index; } System.out.print(target); } }