Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P06leftAndRightSum {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int leftSum = 0;
- int rightSum = 0;
- for(int i=1; i<= n * 2; i++){
- int currentNumber = Integer.parseInt(scanner.nextLine());
- if (i <= n) {
- leftSum += currentNumber;
- } else{
- rightSum += currentNumber;
- }
- }
- int diff =Math.abs (leftSum - rightSum);
- if(diff == 0){
- System.out.printf("Yes, sum = %d", leftSum);
- } else {
- System.out.printf("No, diff = %d",diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment