Question: How do I fix this error? The Coding Language is Java . public class AppleOrange { public static void main(String[] args) { int x =
How do I fix this error? The Coding Language is Java.
public class AppleOrange {
public static void main(String[] args) {
int x = Integer.valueOf(args[0]);
for (int i = 0; i <= x ; i++) {
if (i%3==0) {
System.out.print("apple");
}
else if (i%7==0) {
System.out.print("orange");
}
else if (i%3 == 0 || i%7 == 0) {
System.out.print("appleorange");
}
else {
System.out.print(i + " ");
}
}
}
}
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at AppleOrange.main(AppleOrange.java:5)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
