Java Training Course/JT04: Difference between revisions

From tehowiki
Jump to navigation Jump to search
imported>Gfis
new
 
imported>Gfis
Bonus
Line 8: Line 8:
  java DupInt 2 -4
  java DupInt 2 -4
  java DupInt 0 -1
  java DupInt 0 -1
* Bonus question: What will happen if you run the program without any parameter?

Revision as of 19:21, 22 September 2017

  • Create a file DupInt.java by copying the program DupString.java from JT03, rename the class and replace 3 lines:
       int st0 = Integer.parseInt(args[0]); // the 1st parameter on the commandline
       int st1 = Integer.parseInt(args[1]); // the 2nd ...
       int st2 = st0 + st1;
  • Compile
  • Predict the output of:
java DupInt 2 4
java DupInt 2 -4
java DupInt 0 -1
  • Bonus question: What will happen if you run the program without any parameter?