用最笨但是最省心的写法……
1 import java.util.Scanner; 2 3 public class P1068 4 { 5 public static void main(String args[]) 6 { 7 try (Scanner cin = new Scanner(System.in)) 8 { 9 while (cin.hasNext()) 10 { 11 int n = cin.nextInt(); 12 int result = 0; 13 if (n < 1) 14 for (int i = n; i <= 1; i++) 15 result += i; 16 else 17 for (int i = 1; i <= n; i++) 18 result += i; 19 System.out.println(result); 20 } 21 } 22 } 23 }
时间: 2024-12-30 10:17:55