Suppose you run a Java program on with the command java Hell
Solution
import java.util.*;
public class allmain {
public static void main(String[] args) {
System.out.println(args[4]);
}
}
output for the above program is:
pretty;
and input i had given is:
hello anyone lived in preety how town
when we run this program
hello goes to argument 0
that is=args[0]=hello
args[1]=anyone
args[2]=lived
args[3]=in
args[4]=preety
args[5]=how
args[6]=town
these are stored in these arguments..and we printed only argument 4 so.we see preety in console.
supose if we want to print arguement 5.let us see output:
output is how:
now see for argument 7
output is:
Exception in thread \"main\" java.lang.ArrayIndexOutOfBoundsException: 7
at allmain.main(allmain.java:5)
it throws an execption called array index out of bounds...i,e is we are accessing element beyond limit.and it is not possible
![Suppose you run a Java program on with the command java Hello Anyone lived in a pretty how town What will the value of args[4] in the main method be? Suppose y Suppose you run a Java program on with the command java Hello Anyone lived in a pretty how town What will the value of args[4] in the main method be? Suppose y](/WebImages/34/suppose-you-run-a-java-program-on-with-the-command-java-hell-1098963-1761580211-0.webp)