--> "Solve Me First" HackerRank Solution » In Java

“Solve Me First” HackerRank Solution

solve me first

Objective:

The “Solve Me First” problem on HackerRank is a basic programming challenge that helps beginners get started with writing and running code. The task is to write a function that takes two integers as input and returns their sum.

Problem Description of Solve Me First

You need to write a function that:

  1. Takes two integer inputs.
  2. Returns their sum.

Example 1

Input:

  • a = 2
  • b = 3

Output:

  • 5

Explanation: The sum of 2 and 3 is 5.

Example 2

Input:

  • a = 10
  • b = 5

Output:

  • 15

Explanation: The sum of 10 and 5 is 15.

Example 3

Input:

  • a = -1
  • b = 1

Output:

  • 0

Explanation: The sum of -1 and 1 is 0.

Example 4

Input:

  • a = 0
  • b = 0

Output:

  • 0

Explanation: The sum of 0 and 0 is 0.

Example 5

Input:

  • a = 123
  • b = 456

Output:

  • 579

Explanation: The sum of 123 and 456 is 579.

Steps to Solve:

  1. Read the Input: Take two integers as input.
  2. Calculate the Sum: Add the two integers.
  3. Return the Result: Output the sum of the two integers.
solve me first
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {


    static int solveMeFirst(int a, int b) {
      	// Hint: Type return a+b; below 
        return a+b;
   }

 public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a;
        a = in.nextInt();
        int b;
        b = in.nextInt();
        int sum;
        sum = solveMeFirst(a, b);
        System.out.println(sum);
   }
}
The Problem Solution

One thought on ““Solve Me First” HackerRank Solution

Leave a Reply

Your email address will not be published. Required fields are marked *