Code Logo

Sum of Two Values

Published at19 Apr 2026
Easy 1 views
Like12

This is a great starting point for anyone learning pseudocode. In Sum of Two Values, the goal is simple: you receive two separate numbers as input and your job is to find what happens when you add them together.

Think of it as a basic calculator. You take the first value, add the second one, and then return the total result. It’s a foundational exercise to help you get used to handling numbers and performing basic arithmetic in your algorithms.

For example, if the first number is 10 and the second is 20, your program should output 30. If they are 5 and -3, the result would be 2. It really is that straightforward!

Example Input & Output

Example 1
Input
nums = [0]
Output
true
Explanation

A single element vacuously satisfies the alternating rule.

Example 2
Input
nums = [2,5,6,3]
Output
true
Explanation

The sequence alternates even, odd, even, odd.

Example 3
Input
nums = [1,3,5]
Output
false
Explanation

Two odd numbers appear consecutively.

Algorithm Flow

Recommendation Algorithm Flow for Sum of Two Values
Recommendation Algorithm Flow for Sum of Two Values

Solution Approach

This challenge is an introduction to the basic structure of a pseudocode program. A standard solution involves three main steps: declaration, input, and processing.

program sum_calculation kamus x, y, total: integer algoritma input(x, y) total <- x + y output(total) endprogram

The kamus section is used for variable declaration, where we define x, y, and total as integers. In the algoritma section, we use input(x, y) to capture data, calculate the sum using the assignment operator <-, and finally display the result with output().

Best Answers

java - Approach 1
class Solution {
    public boolean is_alternating(Object nums) {
        int[] arr = (int[]) nums;
        if (arr.length <= 1) {
            return true;
        }
        for (int i = 0; i < arr.length - 1; i++) {
            if ((arr[i] % 2) == (arr[i+1] % 2)) {
                return false;
            }
        }
        return true;
    }
}