Home java Production of squares of the first two hundred numbers

# Production of squares of the first two hundred numbers

Author

Date

Category

It is necessary to make a program to find the work of the squares of the first two hundred numbers.
That’s what I tried:

``````LONG S = 1;
int j;
For (int i = 1; i & lt; = 200; i ++) {
j = (int) math.pow (i, 2);
s * = j;
}
System.out.printLN (S);
``````

displays 0, as it seems to go beyond Long. How else can you solve this task?

in Java and in other languages ​​there are large numbers. Biginteger and Bigdecimal .

``````biginteger a = biginteger.valueof (2147483647);
Biginteger B = Biginteger.Valueof (2147483641);
// A * = B;
// So it is impossible, since these are objects, and not primitives
a = a = a.multiply (b);
// So it is possible - remember that the use of this F-connection does not change this object -
// it returns new
``````

Need to rewrite:

``````biginteger s = biginteger.valueof (1);
For (int i = 2; i & lt; = 200; i ++) {
s = s.multiply (BigInteger.Valueof ((Long) I * i));
}
System.out.printLN (S);
``````

Accordingly, the output will be as follows:

621981231756379489999997501700030226361030042908402135795585416076780567701229627071194748755274771867550481130867332728398608915678217606208944334143532903157416015053231992085653846275159616127812272870349795208758168675609821292383968189620347359298821336964567268936282003057371855944848505049857604569455105033587666178052186125598590101814860460233644389300432456960009702905584857393518877079243717213370983146491503406155228997954249347719005783769360467152555665800216223615428450836858053400856713359967484823371026535062161096211713506798207812398746913836648755132232834523663952442186966337759051603462287553956523494664588575257708095078400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.