Parameters of Main, Sum Learn programming Java

Lesson:

Functions


Exercise:

Parameters of Main, Sum


Objetive:

Create a program named "sum", which receives two integer numbers in the command line and displays their sum, as in this example:

sum 5 3
8


Code:

public class Main
{
	public static void main(String[] args)
	{
		if (args.length == 2)
		{
			System.out.println(Integer.parseInt(args[0]) + Integer.parseInt(args[1]));
		}
		else
		{
			System.out.println("Two numbers, please");
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.