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

11) Write a method (including header and body) that takes as an input an array o

ID: 3724676 • Letter: 1

Question

11) Write a method (including header and body) that takes as an input an array of doubles and f three doubles containing the average, the maximum and the minimunm values of the input array. Test the program by calling the method from the main method. For example Input: 1 2 3 45 Output: 3 5 1 12) Write a Java method that takes a string as an argument and returns the reverse the string. Test the program by calling the method from the main method. reverseString("Hello") "olleH" reverseString("Bye") "eyB"

Explanation / Answer

Solution::

(11)

Source Code::-

import java.util.Scanner;

class Array_Sum

{

public static void sum_avg_max_min(int num[],int n){

//Method will print avg,min and max of the given array.

int min=0,max=0,avg=0,sum=0; //variable declaration.

int element[]=new int[3]; //variable declaration.

for (int i =0;i<n;i++){ //looping all the number present in the array.

sum=sum+num[i]; //finding sum.

if (i==0){ //if i==0 it means it is first element of the array.

max=num[i];//Assign first element of array in the max.

min=num[i];//Assign first element of the array in the min.

}

if (num[i] > max)//If num[i] position is greater than max.

max=num[i];//then update the value of max element.

if (num[i] < min)//If num[i] position is less than min .

min=num[i];//Then update the value of min element.

}

avg=sum/n; //Finding average

element[0]=avg; //Oth position is avg

element[1]=max;//1th position is max

element[2]=min;//2nd position is min.

for (int i=0;i <=2;i++)

System.out.print(element[i]+" "); //Printing all the values.

}

public static void main(String args[])

{

int n;

Scanner s = new Scanner(System.in);

System.out.print("Enter no. of elements you want in array:");

n = s.nextInt();

int a[] = new int[n];

System.out.print("Enter all the elements:");

for(int i = 0; i < n; i++) //Storing all the number in array.

a[i] = s.nextInt();

sum_avg_max_min(a,n); //calling sum_avg_max_min method.

  

}

}

Output::-

(12)

Source Code::-

import java.util.*;

class ReverseString

{

public static void reverse_string(String original){

String reverse="";

int length = original.length();//Finding length of the given string.

for ( int i = length - 1 ; i >= 0 ; i-- ) //Taking each character in reverse order.

reverse = reverse + original.charAt(i);//storing all the character in reverse order.

System.out.println("Reverse of entered string is: "+reverse);

}

public static void main(String args[])

{

String original;

Scanner in = new Scanner(System.in);

System.out.println("Enter a string to reverse");

original = in.nextLine();

reverse_string(original);//Calling reverse_string method.

  

}

}

Output::-

Enter a string to reverse
Hello
Reverse of entered string is: olleH

Enter a string to reverse
Bye
Reverse of entered string is: eyB

Enter no. of elements you want in array:4
Enter all the elements:23
34
56
78
47 78 23 ----------47 is avg,78 is max and 23 is min .
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