Untitled

mail@pastecode.io avatar
unknown
java
a year ago
817 B
9
Indexable
Never
package metode_1;
import java.math.BigInteger;
import java.util.Scanner;
public class metode_1_7 {
    public static String sumOfPerfectSquares(int limit){
        BigInteger sum = new BigInteger("0");

        for(int i = 1; i <= limit; i++){
            BigInteger bdI = new BigInteger(Integer.toString(i));
            sum = sum.add(bdI.multiply(bdI));
        }

        if(sum.toString().length() > 9){
            return sum.toString().substring(sum.toString().length() - 9);
        }
        return sum.toString();
    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        System.out.print("Insert a number:");
        int number = scan.nextInt();

        System.out.println(sumOfPerfectSquares(number));
        scan.close();
    }
}