Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Java_06ForLoop;
- import java.util.Scanner;
- public class Lab0606LeftAndRightSum {
- 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 = 0; i < n; i++)
- {
- int num = Integer.parseInt(scanner.nextLine());
- leftSum += num;
- }
- for(int i = 0; i < n; i++)
- {
- int num = Integer.parseInt(scanner.nextLine());
- rightSum += num;
- }
- if(leftSum == rightSum){
- System.out.println("Yes, sum = " + leftSum);
- }
- else{
- int difference = Math.abs(leftSum - rightSum);
- System.out.println("No, diff = " + difference);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement