Command-line arguments: -These are the values we pass to main() from the command line. Note: Observe the parameter type of main()--->Its a String type array. Example: Q) class Check{ public static void main(String[] ar){ System.out.println(ar[0]); System.out.println(ar[1]); } } File name: Check.java Compilation: >javac Check.java Execution: >java Check hello hi hello hi ......................................................... Q) class Check1{ public static void main(String[] ar){ System.out.println(ar[0]+ar[1]); } } File name: Check1.java Compilation: > javac Check1.java Execution: > java Check1 10 20 1020 ........................................................ Q) class Check2{ public static void main(String[] ar){ int x=Integer.parseInt(ar[0]);//parseInt() converts 'String' value to its corresponding 'int' type value int y=Integer.parseInt(ar[1]); System.out.println(x+y); } } File name: Check2.java Compilation...
Posts
Showing posts from July, 2016