java - ArrayIndexOutOfBoundException when run my simple code -
i write simple code understanding passing value manually, there code
public class coba{ public static void main (string[] args){ int a; int b; a= integer.parseint(args [0]); b= integer.parseint(args [1]); int c=0; c= a+b; system.out.println("jumlah "+c); } }
why arrayindexoutofboundexception?? , how solve can pass values of , b manually? answer :)
well presumably you're not passing in 2 command-line arguments. should fine if run with:
java coba 10 20
for example.
you can validate @ start using args.length
:
public static void main (string[] args){ if (args.length < 2) { system.out.println("i need 2 command line arguments!"); return; } int = integer.parseint(args[0]); int b = integer.parseint(args[1]); int c = + b; system.out.println("jumlah "+c); }
Comments
Post a Comment