17/01/25 ---------- Q)How to access the elements of an array? =>To access each element individually, we use array name along with index. For eg. int a[]=new int[5]; a[0]=10; a[2]=20; a[3]=30; a[4]=40; a[5]=50; System.out.println(a[0]); System.out.println(a[1]); System.out.println(a[2]); System.out.println(a[3]); System.out.println(a[4]); =>To traverse an array we can use either enhanced for loop or normal for loop. Note:- Accessing each element of the array one by one is known as traversing. Q)Java program to initialize an integer array of 5 elements and display them. //traversing an array with a for loop class ArrayExample{ public static void main(String[] args){ int a[]={10,20,30,40,50}; for(int i=0;ivalues supplied to main method from the command line are known as commandline arguments. Note:- JVM receives the values from the commandline, constructs an array object with those values and then calls the main method. Q)Write a Java program to display all the supplied command line arguments. class CommandLineTest{ public static void main(String []args){ for(String ca:args){ System.out.println(ca); } } }//java CommandLineTest Java Spring AWS Q)Java program to add the two numbers supplied from the commandline,add them and display the sum. class CommandLineTest{ public static void main(String []args){ int n1=Integer.parseInt(args[0]); int n2=Integer.parseInt(args[1]); int sum=n1+n2; System.out.println("The sum is "+sum); } }//java CommandLineTest 10 20 OR class CommandLineTest{ public static void main(String []args){ int sum=0; for(String s:args){ sum=sum+Integer.parseInt(s); } System.out.println("The sum of "+args.length+" numbers is "+sum); } }//java CommandLineTest 10 20