Sunday, 2 March 2014

Command Line Parameters in Java (3)

If you need to supply two or more parameters, separate each parameter from the next with a space as shown below:

andrew@UBUNTU:~/Java$ cat prog36.java
public class prog36
{
public static void main(String[] args)
  {
  int x = Integer.parseInt(args[0]);
  int y = Integer.parseInt(args[1]);
  int z = x + y;
  System.out.println
  (x + " + " + y + " = " + z);
  }
}
andrew@UBUNTU:~/Java$ javac prog36.java
andrew@UBUNTU:~/Java$ java prog36 3 8
3 + 8 = 11
andrew@UBUNTU:~/Java$ java prog36 -5 11
-5 + 11 = 6
andrew@UBUNTU:~/Java$