Question

Java Python mirrorLength Well say that a mirror section in an array is a group of contiguous elements such that somewhereHas to be in Java programming language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Hey! kindly find your solution below. Let me know if any issue. Thanks.

This java program has a method to find mirror length is a given array taking an array as a parameter and return mirror length. All possible screenshots of outputs screenshots are attached. If any prob comments me in the comment box.

Java Code:

import java.util.*;
class Main
{
//method to return mirror length in given array
public static int mirrorLength(int[] arr)
{
int len = arr.length;//find array length
int count= 0; //needed variables
int mirr = 0;

if(len==0)
{
return 0;
}
  
for (int i = 0; i < len; i++) //loop to array length
{
count=0;
//to check mirror elements
for (int k = len-1; i + count < len && k > -1; k--)
{
if(arr[i+count] == arr[k])//if found increment count
{
count++;
}
else
{
if (count > 0)//if count >0
{
mirr = Math.max(count,mirr);//find max and store into mirr variable
count = 0;
}
}
}
mirr = Math.max(count,mirr);//find max
}
return mirr;//return mirror length
}

public static void main(String []args)
{
int [] arr1 = {7,1,2,9,7,2,1};//array given to find mirror length
int ans;
ans = mirrorLength(arr1);//call method
System.out.println("Mirror Length: "+ans);
}
}

34 public static void main(String []args) 35 { 36 int [] arr1 = {1,2,3,8,9,3,2,1};//array given to find mirror Length int ans

36 int [] arri {1,2,1,4};//array given to find mirror Length 37 int ans; 38 ans = mirrorLength(arri);//call method 39 System.

37 35 36 int [] arri {7,1,2,9,7,2,1};//array given to find mirror Length int ans; 38 ans = mirrorLength(arr1);//call method 3

Add a comment
Know the answer?
Add Answer to:
Has to be in Java programming language Java Python mirrorLength We'll say that a "mirror" section...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CMSC 200 (Computer Programming - Java 10.0.2) We'll say that a value is "everywhere" in an...

    CMSC 200 (Computer Programming - Java 10.0.2) We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that value. Return true if the given value is everywhere in the array. Examples: isEverywhere( [1, 2, 1, 3], 1 ) -> true isEverywhere( [1, 2, 1, 3], 2 ) -> false isEverywhere( [1, 2, 1, 3, 4], 1 ) -> false

  • PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE...

    PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE 11. Initialize a integers in the two-dimensional array testArray to the values 1 through 9 using 1 or more while loops so that the array could be visualized as: 1 2 3 LA 5 6 7 8 9...

  • Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps....

    Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps. This is a basic course and the furthest we have gone is BASIC arrays. Write the code for the following problems using arrays. Write what would go in the “int main()” part of the program. For these problems, the entire program and program output is not needed. Just include what goes in the int main() part of the program. 1. Declare an integer array...

  • I need help with these java codingbat questions please: Create a method that creates a user...

    I need help with these java codingbat questions please: Create a method that creates a user id, where the user id is made up of the first letter of the first name and the entire last name. e.g. john smith ->jsmith getUserld("bill", "gates")-"bgates" getUserId("steve", "jobs")"sjobs" getUserId("larry", "page") -"lpage" Go Save, Compile, Run (ctrl-enter) public String getUserId( String firstName, String lastName) Given a number n, create an array with elements starting from 1 to n. e.g. 5 > getNumArray(1) [1] getNumArray...

  • This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string...

    This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...

  • Please write a Java program: Given an array of positive integers, return a count of the...

    Please write a Java program: Given an array of positive integers, return a count of the number of even integers. countEvens([2, 3, 5])-1 countEvens([4, 20]) - 2 countEvens([3, 7, 1, 11]) 0 Go Save, Compile, Run (ctrl-enter) int countEvens (int[] nums) {

  • the programming language is in java Problem 2 You are given an array A with n...

    the programming language is in java Problem 2 You are given an array A with n distinct elements. Implement an (n log n)-time algorithm that creates an array B where all elements are in range from 0 to n - 1 and where the order of elements is the same as in A. That is, 0 has the same index in B as the smallest element in A, 1 has the same index in B as the second smallest element...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • Loops | Methods | Arrays(programming language java) in software (ATOM) Write a toolkit that includes some...

    Loops | Methods | Arrays(programming language java) in software (ATOM) Write a toolkit that includes some common functions a user might want or need An encryption/ decryption method. Both methods should take in a String (the String that needs to be changed), and an encryption value. The methods need to change the String by the value Write a method that takes an integer array as an argument. The method should return the sum of all of the elements Write a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT