Java programs that does the following: Given a string, return all 3 character su
ID: 3742200 • Letter: J
Question
Java programs that does the following:
Given a string, return all 3 character substrings of that string in an arraylist. That is, first it will return the 1st 3 characters of the string. Then it will return the 2nd 3rd and 4th characters.Then it will return the 3rd 4th and 5th characters
Given two arrays, count the number of times the first array occurs in the second array. You can assume that the first array is shorter than the second.
iven two arrays of integers that are the same length, returns a new array that contains the pairwise max of the corresponding elements of the original arrays (i.e. the larger of the two numbers in that slot in the original arrays) ex: maxArray({2,10},{1,200}) returns {2,200}
Explanation / Answer
Please find the code below.
CODE
===================
import java.util.ArrayList;
public class Main
{
public static ArrayList<String> getSubStrings(String s) {
ArrayList<String> subStrings = new ArrayList<>();
for(int i=0; i<= s.length()-3; i++) {
subStrings.add(s.substring(i, i+3));
}
return subStrings;
}
public static int getCount(int a[], int b[]) {
int count = 0;
for(int i=0; i<a.length; i++) {
for(int j=0; j<b.length; j++) {
if(a[i] == b[j])
count ++;
}
}
return count;
}
public static int[] getMaxArray(int a[], int b[]) {
int result[] = new int[a.length];
for(int i=0; i<a.length; i++) {
result[i] = Math.max(a[i], b[i]);
}
return result;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.