Talk:Java Training Course/JT04: Difference between revisions

From tehowiki
Jump to navigation Jump to search
imported>Gfis
Created page with " 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..."
 
imported>Gfis
No edit summary
Line 1: Line 1:
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
  georg@nunki:~/work/project/bekasi/JTC$ java DupInt 2 4
24
  24
  georg@nunki:~/work/project/bekasi/JTC$ java DupInt 2 -4
  georg@nunki:~/work/project/bekasi/JTC$ java DupInt 2 -4
  -8
  -8

Revision as of 19:55, 23 September 2017

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)