Question
The following code gives this excetion when ran. It runs the initial loop for the the numbers prompt but throws this when the rest runs
The following code gives this excetion when ran. It runs the initial loop for the the numbers prompt but throws this when the rest runs : "
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 51
at Homework9.add(Homework9.java:79)
at Homework9.main(Homework9.java:15)
------------------------------------------------------------
import java.util.*; public class Homework9 {
public static void main(String[] args) { int [] a= new int[51]; int [] b= new int[51]; int [] c= new int[51]; Scanner in=new Scanner(System.in); a = longInt("first number: ",in); b = longInt("second number: ",in); c = add(a,b); System.out.print(" "); print(a); System.out.print("+ "); print(b); //adding interface for(int i=0;i //alignment method public static int[] longInt(String usernumber,Scanner in) { int i; int [] a = new int[51]; for(i=0;i<50;i++) a[i]=0; String input; System.out.print("Enter "+usernumber); input=in.next(); a[0]=input.length(); for(i=0;i
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