Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started