Talk:Java Training Course/JT04

From tehowiki
Revision as of 19:55, 23 September 2017 by imported>Gfis
Jump to navigation Jump to search

Complete program:

public class DupInt {
    public static void main(String[] args) {
        int st0 = Integer.parseInt(args[0]); // the 1st parameter on the commandline
        int st1 = Integer.parseInt(args[1]); // the 2nd ...
        int st2 = st0 + st1;
        st2 = st2 + st2 + st2 + st2;
        System.out.println(st2);
    } // main
} // DupInt

Output with different arguments:

georg@nunki:~/work/project/bekasi/JTC$ java DupInt 2 4
 24
georg@nunki:~/work/project/bekasi/JTC$ java DupInt 2 -4
-8
georg@nunki:~/work/project/bekasi/JTC$ java DupInt 0 -1
-4
georg@nunki:~/work/project/bekasi/JTC$ java DupInt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at DupInt.main(DupInt.java:3)