Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Arrays; import java.util.Scanner; public class FindAll { / * * Finds the positions of all occurrences of an element in an array. @param values

import java.util.Arrays;
import java.util.Scanner;
public class FindAll
{
/**
Finds the positions of all occurrences of an element in an array.
@param values an array of values
@param searchedValue the value to search for
@param the positions of all matches
*/
public static int[] findAll(int[] values, int searchedValue)
{
int[] result = new int[/* Your code goes here */];
int resultSize =0;
int pos =-1;
do
{
pos = findNext(values, searchedValue, pos +1);
if (/* Your code goes here */)
{
/* Your code goes here */
}
} while (/* Your code goes here */);
/* Your code goes here */
}
/**
Finds the next occurrence of an element in an array.
@param values an array of values
@param searchedValue the value to search for
@param start the position at which to start the search
@return the position of the first match at position >= start,
or -1 if the element was not found
*/
public static int findNext(int[] values, int searchedValue, int start)
{
/* Your code goes here */
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String arrStr = in.nextLine();
String[] strArray = arrStr.split("");
int[] intArray = new int[strArray.length];
for (int i =0; i < strArray.length; i++)
{
intArray[i]= Integer.parseInt(strArray[i]);
}
int searchedValue = in.nextInt();
System.out.println(Arrays.toString(findAll(intArray, searchedValue)));
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Identify how culture affects appropriate leadership behavior

Answered: 1 week ago