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::-
| 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 . |
(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 Enter a string to reverse |
11) Write a method (including header and body) that takes as an input an array of...
java code
Write a method called reverse that takes an array of integers as an input and returns the same values in reverse order as the output. Test your method in the main.
RUBY! \Write a method called reverse_each_word that takes in a string argument of a sentence and returns that same sentence with each word reversed in place. First solve it using .each Then utilize the same method using .collect to see the difference. For example: reverse_each_word("Hello there, and how are you?") #=> "olleH ,ereht dna woh era ?uoy" Hint: You can't use an enumerator on a string, so how can we turn our string into an array? Hint: How can we...
In JAVA: Write a method that reverses the array passed the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers and display the numbers. Write a method that returns a new array by eliminating the duplicate values in the array using following method header: a. Public static int[] eliminateDuplicates(int list) b. Write a test program that reads in ten integers and invoke the method, the...
JAVA PLEASE!
Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...
Write a java program that has a method called sameArrayBackwards. The method takes an array of integers, and checks if the numbers in the array are the same going forward as going backwards and will return a boolean (true or false) depending on the result. You can assume that there is at least one element in the array. Method Header: public static boolean sameArrayBackwards (int [] arr) You will test your method in the main method of your program by...
Using C,
Write a function reverse which takes a string as an argument, reverses the string and returns the reversed string. Note; you should not return a string that you created inside the reverse function! For example: Test char str[]-"hello" printf("%s", reverse (str)); Result olleh
JAVA Array 3. Write a method called noVowels that takes a String as input and returns true if it doesn't contain any vowels (a, e, i, o, u)
Write a function that takes a string as a parameter and returns a new string that is the reverse of the old string. Python from test import testEqual def reverse(s): return s testEqual(reverse("hello"),"olleh") testEqual(reverse("l"),"l") testEqual(reverse("follow"),"wollof") testEqual(reverse(""),"")
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...
2a) Write a method countEvens that takes an ArrayList of String objects as input and returns the number of even length strings contained in the input. For example, if the input is [ one, peach, pear, plum ] then countEvents(inp) should return 2. 2b) Write a method, mirror, that doubles the size of a list of integers by appending a mirror image of the list. For example, given an array list containing [ 1, 5, 2, 6 ], the method...