Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _2_SumOfElements {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- String lineNumbers = scan.nextLine();
- String[] numStr = lineNumbers.split("[ ]+");
- int maxNum = 0;
- long sumOfNumbers = 0;
- for (int i = 0; i < numStr.length; i++) {
- int nextNum = Integer.parseInt(numStr[i]);
- sumOfNumbers += nextNum;
- if (nextNum > maxNum) {
- maxNum = nextNum;
- }
- }
- sumOfNumbers -= maxNum;
- long difference = Math.abs(sumOfNumbers - maxNum);
- if (difference == 0) {
- System.out.println("Yes, sum=" + sumOfNumbers);
- } else {
- System.out.println("No, diff=" + difference);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement