But see this program....the program will show the run time error(ArrayIndexOutOfBounds) how solve this explain me pls | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

But see this program....the program will show the run time error(ArrayIndexOutOfBounds) how solve this explain me pls

class switchdemo { public static void main(string[]args) { int color; color= Integer.parseInt(args[0]); switch(color) ( case 1: System.out.println("GREEN"); break; case 2: System.out.println("RED"); break; default: System.out.println("invalid number"); }}}

28th Mar 2017, 12:53 AM
E Farid
E Farid - avatar
2 Answers
+ 8
args.length is 0 So It's mean no value n array inside args ArrayIndexOutOfBoundsException is error that um.....Why I always have a disease?!.I'm not good at explain again. Jump to example then int[] a = {1,2,3}; System.out.print(a[3]); No [3] inside the variable a that is error. Sum : Out of array's size Btw I need some milk
28th Mar 2017, 1:54 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
Where are you passing the value in the program to the array?
28th Mar 2017, 1:25 AM
Hassie
Hassie - avatar