Home java Production of squares of the first two hundred numbers

Production of squares of the first two hundred numbers




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?

Answer 1, Authority 100%

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:


Programmers, Start Your Engines!

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.

Recent questions