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!

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"); }}}

pls

3/28/2017 12:53:54 AM

E Farid

2 Answers

New Answer

+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

+1

Where are you passing the value in the program to the array?