This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following code:public class Test { public static void main(String[] args) {int[] x = {1, ... (Read 29 times)

vinney12

  • Hero Member
  • *****
  • Posts: 586

Question 1

Fill in the code to complete the following method for checking whether a string is a palindrome.

public static boolean isPalindrome(String s) {
if (s.length() <= 1) // Base case
return true;
else if ________
return false;
else
return isPalindrome(s.substring(1, s.length() - 1));
}

◦ (s.charAt(0) != s.charAt(s.length())) // Base case
◦ (s.charAt(1) != s.charAt(s.length() - 1)) // Base case
◦ (s.charAt(0) != s.charAt(s.length() - 1)) // Base case
◦ (s.charAt(1) != s.charAt(s.length())) // Base case

Question 2

Analyze the following code:

public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4, 5};
xMethod(x, 5);
}

public static void xMethod(int[] x, int length) {
System.out.print(" " + x[length - 1]);
xMethod(x, length - 1);
}
}

◦ The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.
◦ The program displays 5 4 3 2 1.
◦ The program displays 1 2 3 4 6.
◦ The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by vinney12 on May 6, 2020

matt95

  • Sr. Member
  • ****
  • Posts: 317
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




vinney12

  • Member
  • Posts: 586
Reply 2 on: May 6, 2020
Great answer, keep it coming :)


kishoreddi

  • Member
  • Posts: 329
Reply 3 on: Yesterday
Wow, this really help

 

Did you know?

Blood in the urine can be a sign of a kidney stone, glomerulonephritis, or other kidney problems.

Did you know?

Elderly adults are at greatest risk of stroke and myocardial infarction and have the most to gain from prophylaxis. Patients ages 60 to 80 years with blood pressures above 160/90 mm Hg should benefit from antihypertensive treatment.

Did you know?

Children of people with alcoholism are more inclined to drink alcohol or use hard drugs. In fact, they are 400 times more likely to use hard drugs than those who do not have a family history of alcohol addiction.

Did you know?

Illicit drug use costs the United States approximately $181 billion every year.

Did you know?

It is believed that the Incas used anesthesia. Evidence supports the theory that shamans chewed cocoa leaves and drilled holes into the heads of patients (letting evil spirits escape), spitting into the wounds they made. The mixture of cocaine, saliva, and resin numbed the site enough to allow hours of drilling.

For a complete list of videos, visit our video library