From f0ff63fa7401c7afc2eb9ae84246d60cc2d40e25 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar <36505624+itisabhishekkumar@users.noreply.github.com> Date: Sun, 14 Oct 2018 20:15:30 +0530 Subject: [PATCH] Cleared Code --- SOLUTIONS/Find Sum square Difference.java | 46 +++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/SOLUTIONS/Find Sum square Difference.java b/SOLUTIONS/Find Sum square Difference.java index 6d327cf5..64554a76 100644 --- a/SOLUTIONS/Find Sum square Difference.java +++ b/SOLUTIONS/Find Sum square Difference.java @@ -1,25 +1,31 @@ import java.util.Scanner; -public class Solution { +public class SumSquareDifference { - private static final Scanner scanner = new Scanner(System.in); + private static final Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + + String total = scanner.nextLine(); + + int n = Integer.parseInt(total); + + for (int i = 0; i < n; i++) + { + String next = scanner.nextLine(); + int number = Integer.parseInt(next); + int squareSum = 0; + int sum = 0; + for (int j = 1; j <= number; j++) { + squareSum = squareSum + j * j; + sum = sum + j; + } + int sumSquare = sum * sum; + int difference = squareSum - sumSquare; + System.out.println(String.valueOf(difference > 0 ? difference : -difference)); + } + scanner.close(); + + } - public static void main(String[] args) { - String total = scanner.nextLine(); - int n = Integer.parseInt(total); - for (int i = 0; i < n; i++) { - String next = scanner.nextLine(); - int number = Integer.parseInt(next); - int squareSum = 0; - int sum = 0; - for (int j = 1; j <= number; j++) { - squareSum = squareSum + j * j; - sum = sum + j; - } - int sumSquare = sum * sum; - int dif = squareSum - sumSquare; - System.out.println(String.valueOf(dif > 0 ? dif : -dif)); - } - scanner.close(); - } }