Home‎ > ‎Applied Core Java‎ > ‎Introduction‎ > ‎

Division

Problem : Write a program that divide integer taken from command line as an argument ?

Program :

Step 1 - Coding

Create a text file c:\sunilos\Division.java  and copy below contents.

/*

 * A program which take two integer from command line argument and divide.
 */

public class Division {

    public static void main(String[] args) {

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

        double div = a/b;

        System.out.println("Division is " + div);
    }
}

Step 2 - Deployment

  1. Create a folder 'c:\sunilos'. 
  2. Create or copy Division.java  into 'c:\sunilos' folder.
  3. Open your command prompt and go to  'c:\sunilos'
  4. Compile Division.java with help of 
    • javac Division.java command. Command will create class file in the same folder.
  5. Congratulations!! your Java program is ready to serve.

Step 3 - Testing

  1. Make sure you are on Command Prompt under c:\sunilos directory
  2. Now start your java program from command prompt with help of 
    • java Division 10 5 command.

Output


It will display
Division is 2.0

<<Previous | Next>>
ċ
Division.java
(0k)
nakul shukla,
Mar 19, 2009, 7:19 AM
Comments