Java Training Course/JT04: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
imported>Gfis  new  | 
				imported>Gfis No edit summary  | 
				||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
* Create a file <code>DupInt.java</code> by copying the program <code>DupString.java</code> from [[Java Training Course/JT03|JT03]], rename the class and replace 3   | ==Integer Arithmetic==  | ||
         int st0 = Integer.parseInt(args[0]); // the 1st   | * Create a file <code>DupInt.java</code> by copying the program <code>DupString.java</code> from [[Java Training Course/JT03|JT03]], rename the class and replace lines 3 to 5 with:  | ||
         int st0 = Integer.parseInt(args[0]); // the 1st argument on the commandline  | |||
         int st1 = Integer.parseInt(args[1]); // the 2nd ...  |          int st1 = Integer.parseInt(args[1]); // the 2nd ...  | ||
         int st2 = st0 + st1;  |          int st2 = st0 + st1;  | ||
| Line 8: | Line 9: | ||
  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 argument?  | |||
[[Java Training Course/JT03|< Previous: JT03]] Main Arguments and String Concatenation<br />  | |||
[[Java Training Course/JT05|> Next: JT05]] Greatest Common Divisor  | |||
Latest revision as of 09:54, 24 September 2017
Integer Arithmetic
- Create a file 
DupInt.javaby copying the programDupString.javafrom JT03, rename the class and replace lines 3 to 5 with: 
       int st0 = Integer.parseInt(args[0]); // the 1st argument 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 argument?
 
< Previous: JT03 Main Arguments and String Concatenation
> Next: JT05 Greatest Common Divisor