Topic Description:
For 1+2+3+...+n, it is not possible to use the key words such as multiplication and division, for, while, if, else, switch and case, etc. B:C).
Input:
The input may contain more than one test sample. For each test case, enter an integer n (1<= n<=100000).
Output:
For each test case, output the 1+2+3+...+n value.
Sample input:
3
5
Sample output:
6
15
This topic is really boring, try to write in the Java language, the construction method, finally, there is no way, or to use for, the construction of an object array is not false, but that people call is to create the array reference object constructor, but also to instantiate the object n times in the array, and forced me to use for loop, this is just, The test results timed out, and the key is that the time for each test case does not timeout, but the total time has expired.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Do not want to waste time on this boring topic, just like this, there is a time no Java, hands are born, in addition, the use of Java constructor ideas to do this topic, there is no for the loop can calculate the answer, welcome hint, really do not want to think!
Anyway, put the code on it!
Import java.util.*;
public class main{public
static void Main (String args[]) {
Scanner cin = new Scanner (system.in);
int n;
while (Cin.hasnext ()) {
n = cin.nextint ();
Temp.reset ();
Temp arr[] = new Temp[n];
for (int i=0;i<n;i++)
arr[i] = new Temp ();
System.out.println (Temp.getsum ());
}} Class temp{
private static int n = 0;
private static int sum = 0;
public static void Reset () {
n = 0;
sum = 0;
}
Public Temp () {
++n;
sum = n;
}
public static int Getsum () {return
sum;
}
}