|
|
back to boardDiscussion of Problem 1068. Sumwa9. Posted by Andrew 27 Nov 2016 17:21 import java.util.*; public class JavaApp { public static void main(String[] args) { int i=0; Scanner scan = new Scanner(System.in); int n=scan.nextInt();
if ((n>=1)&&(n<10000)){ i=n *(n + 1) / 2; System.out.print(i);} else if ((n<=1)&&(n>-10000)){ i=-((-n) *(1 -n) / 2) + 1; System.out.print(i);} }; } Re: wa9. Posted by Andrew 6 Feb 2017 17:28 import java.util.Scanner; public class tests {
public static void main(String[] args) { int i=0; Scanner scan = new Scanner(System.in); try{ int n=scan.nextInt(); if ((n>=1)&&(n<=10000)){ i=n *(n + 1) / 2; System.out.print(i);} else if ((n<=1)&&(n>=-10000)){ i=-((-n) *(1 -n) / 2) + 1; System.out.print(i);} } finally { scan.close(); } } } |
|
|