- 1
Please cheak code and tell me error
class programn { public static void main(String args[]) { int i=Integer.parseInt(args[0]); System.out.println("input"+i); } }
8 ответов
+ 2
public class Program {
public static void main(String[] args)
{
if(args.length > 0) {
int i=Integer.parseInt(args[0]);
System.out.println("input"+i);
} else {
System.out.println("No argument given");
}
}
}
+ 13
When nothing is passed as argument to main(), accessing args[0] will cause index out of bounds exception.
+ 2
If you run the program without any additional command line arguments then you will get an array index out of bounds exception. So you may want to add a check for the length of the args array.
+ 2
If you're running it in the playground you won't be able to add the argument. You'd need to run it via the command line on your computer or on another online ide that allows you to add arguments.
+ 1
oh now i understand... thank you guyz for your invaluable help...
thatz mean playground does not support command line argument..
0
what should i do now to remove error??
0
Insert an argument.
0
where did i have to inseart argument?😢