Skip to content
Archive

Kattis Challenge "Sum of Others"

“Every day, your job requires you to add up long lists of integers, like the following: 3 + 2 + -4 + 8 + 3 + -6 + 1 + 4 + 6 + -1 + -6 = 10 That is, a sum of positive and negative integers, followed by an equals sign, followed by a single integer. To save yourself some time, you normally leave out the and signs as you write down your work, so the previous example would be…”

Kattis Challenge "Sum of Others"

Problem

My solution

import java.util.Scanner;
public class SumOfOthers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] temp = sc.nextLine().split(" ");
            int answer = 0;
            for (int i = 0; i < temp.length; i++) {
                answer += Integer.parseInt(temp[i]);
            }
            System.out.println(answer/2);
        }
    }
}

Related Reading

Related entries

Selected from shared tags, categories, and nearby entries in the same section.

Relationship Map

Connected Memory

This relationship map centers on the current entry and highlights connected categories and tags.

Categories 0
Tags 0
Entries 0