Sum of two numbers using command line arguments in Java

 
 

Share on Google+Share on Google+

Java Coder
Sum of two numbers using command line arguments in Java
1 Answer(s)      8 months ago
Posted in : Java Beginners
Ads

Hi,

How to pass two values as parameter from command line and the get in it Java program?

The calculate the sum of two numbers using command line arguments in Java.

Thanks

Ads
View Answers

April 16, 2017 at 6:51 PM


Hi,

While calling Java program from command line you can pass two values a parameter.

For example if your class file name is AddNumbers then you can call like:

java AddNumbers 1 5

Then 1 and 5 will be passed as argument and you can get the value with following code:

  int a = Integer.parseInt(args[0]);
  int b = Integer.parseInt(args[1]);

Now you can calculate the sume

int sum = a+b;

Check complete example code at Add Two Numbers in Java.

Thanks


Ads









Related Tutorials/Questions & Answers:
Sum of two numbers using command line arguments in Java
Sum of two numbers using command line arguments in Java  Hi, How to pass two values as parameter from command line and the get in it Java program? The calculate the sum of two numbers using command line arguments in Java
COMMAND LINE ARGUMENTS
COMMAND LINE ARGUMENTS  JAVA PROGRAM TO ACCEPT 5 COMMAND LINE ARGUMENTS AND FIND THE SUM OF THAT FIVE.ALSO FIND OUT LARGEST AMONG THAT 5   ..._VALUE; int sum=0; System.out.println("Enter 5 numbers
Advertisements
command line arguments - Java Beginners
command line arguments  how can i findout the minimum and maximum no's at the command prompt if i give some values?????????  hi friend... at the command prompt and then calculate the max and min numbers from them
How to pass command line arguments in Java?
How to pass command line arguments in Java?  Hi, In a Java program I have to write for reading the command line arguments and use it in a programming. How to pass command line arguments in Java? Share me the sample code
Command line arguments
Command line arguments  Please explain me what is the use of "command line arguments" and why we need to use
Command Line Arguments in Java Program
command line arguments like: java CmndLineArguments Mahendra zero one two three OUTPUT Command line arguments were passed : Mahendra zero one two... Command Line Arguments in Java Program   
Command Line Arguments in Java
Command Line Arguments in Java The ongoing Java application can accept any... command line arguments in java program. */ class CmndLineArguments { public... of the program: Run program with some command line arguments like: java
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line... take any number of command-line arguments which may be necessary for the program
please tell me about command line arguments in java?
please tell me about command line arguments in java?  please tell me about command line arguments in java?   Hi Friend, The command-line... take any number of command-line arguments which may be necessary for the program
character as command line arguments
character as command line arguments  public class testing { public static void main(String args[]) { char a; a=args[0]; System.out.println("character is:"+a); } } what will be the above program output
how to pass command line arguments in ant
how to pass command line arguments in ant  How to pass runtime values ie commandline arguments to a program written in java using ant tool
Java program to get the Command Line Arguments
Java program to get the Command Line Arguments       In java we can get the command  line...; Getting command line arguments -- Argument [1] is = Amit Argument
Command line arguments
Java application can accept any number of arguments directly from the command line. The user can enter command-line arguments when invoking the application. When running the java program from java command, the arguments are provided
Printing Command Line arguments in JRuby
Printing Command Line arguments in JRuby... we will discuss about printing command line arguments in JRuby program. We can also take arguments from the command line into our JRuby program. 
Add Two Numbers in Java
Add Two Numbers in Java     ... of two numbers! Sum: 32... with command prompt arguments provided by the user. We will access
How To Read String From Command Line In Java
will give the input as command line using the keyboard. Here I am giving the two...How To Read String From Command Line In Java In this section we will discuss about how string can be read through the command line. In Java command line
Command line argument in java
Command line argument in java. In this section we are going to discuss about command line argument in java. Command line argument allow a user to pass arguments at the time of running the application , after the class name. Java allow
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
Passing argument at command line using Core Java
How to pass Command Line Argument using Core Java Description : This example...; } System.out.println("The Sum of All Elements entered at command line...; The Sum of All Elements entered at command line is : 17
Swapping of two numbers in java
Swapping of two numbers in java In this example we are going to describe swapping of two numbers in java  without using the third number in java. We... values from the command prompt. The swapping of two numbers is based on simple
Java Command Line Input
Java Command Line Input  How to get input from command line in java ?   Hi please Find the code for inputting data from the command line System.out.println("Please Input A Number"); BufferedReader br
Passing Command Line Arguments
Passing Command Line Arguments     ... pass values on command line argument . We are taking a sequence of character from command line at run time. Store these strings into an array
What is command line argument in Java
example of command line argument program in Java?? It will be really helpful for the beginners like me.   Command line arguments allow the user... of arguments from the command line. Arguments are passed as a string array
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java
WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java  WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java   
How to add two numbers in Java?
numbers in Java it will return you int value as sum of two numbers. In real world... how to sum(add) two numbers in Java. Check more tutorials at: Java... How to add two numbers in a Java program? In Java you can easily add
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
execute a PHP script using command line
execute a PHP script using command line  How can I execute a PHP script using command line?   Hi friends, Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line
Calculate the Sum of three Numbers
Calculate the Sum of Three Numbers       This is simple java programming tutorial . In this section you will learn how to calculate the sum of three numbers by using three

Ads

 
Advertisement null

Ads