Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( Optional ) Consider the following Test.java file. / / inside main System.out.println ( foo ( Hello ) ) ; / / line 6 /

(Optional) Consider the following Test.java file.
// inside main
System.out.println (foo(Hello)); //line 6
// more line of codes
.....
.....
public static int foo (String s)//line 9
{
if (s.length()==0)
return 0;
else
return (1+ foo (s.substring(0, s.length()-2))); //line 15
}
The code compiles, but when it runs, you get the following output:
Exception in thread main java.lang.StringIndexOutOfBoundException: begin 0, end -1, length 1
at java.base/java.lang.String.checkBoundsBeginEnd(Unknown source)
at java.base/java.lang.String.subString(Unknown source)
at Test.foo(Test.java:15)
at test.foo(Test.java:15)
at Test.foo(Test.java:15)
at test.main(Test.java:6)
Explain what the problem is and how it happens.

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

Step: 3

blur-text-image

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+. Alliteration The Magic of Macy's tagline.

Answered: 1 week ago

Question

=+iv. Simple promise No ordinary airline (Virgin Atlantic Airway).

Answered: 1 week ago