Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, you will write two functions. Function 1: Write a function

ID: 3669280 • Letter: F

Question

For this assignment, you will write two functions.

Function 1:

Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, ... 50. Use recursion to calculate the sum. Demonstrate the function in a program.

Function 2:

Write a recursive function that accepts a string object as its argument and prints the string in reverse order. Demonstrate the function in a driver program.

Explanation / Answer

1.

public static void main(String[] args) {

int[] number = {};
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a number and I will return the sum "+"of all the numbers.");
System.out.println("Exampls: If 50 is entered,the "+"method will return the sum of 1, 2, 3, 4, ... 50");
int num = keyboard.nextInt();
System.out.println("The sum of the numbers are " + rangeSum);
}
public static int rangeSum(int[] num, int start, int end)
{
if (start > end)
return 0;
else
return num[start] + rangeSum(num, start + 1 , end);
}
}

2. it helps you to reverse the string which u gave,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote