Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;ib[0]) n = a[0]; else n=b[0]; for(i=0;i=0;i--) System.out.print(a[51-i]); System.out.println(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

consider your role and influences as a researcher;

Answered: 1 week ago

Question

4. What decision would you make and why?

Answered: 1 week ago

Question

3. Review the evidence. Do you believe the testimony presented?

Answered: 1 week ago

Question

1. What are the marketing implications of this situation?

Answered: 1 week ago