004-010-006

Command Line Arguments: Simple Calculator

Medium

Problem Description

Command Line Arguments: Simple Calculator

Learning Objective: Understand how to receive command line arguments and control program behavior

Overview

Create a program that receives two integers as command line arguments, calculates their sum, and outputs the result.

Specifications

  • Get values from main method argument String[] args
  • Convert args[0] and args[1] to integers (use Integer.parseInt)
  • Calculate and output the sum of the two integers
  • If fewer than 2 arguments, output "Please provide two numbers"

Input Example

Program execution arguments: 25 17

Output Format

Sum: 42

Note: Implement error message for insufficient arguments.

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?