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

/** Given an int array, return an int array with duplicate ints removed if the a

ID: 3696509 • Letter: #

Question

/**
Given an int array, return an int array with duplicate ints removed if the array contains duplicate values.

removeDuplicateInts({3}) → {3}
removeDuplicateInts({1, 2}) → {1, 2}
removeDuplicateInts({7, 7}) → {7}
removeDuplicateInts({1, 7, 1, 7, 1}) → {1, 7}
removeDuplicateInts({1, 2, 3, 4, 5}) → {1, 2, 3, 4, 5})
removeDuplicateInts({1, 2, 3, 2, 4, 2, 5, 2}) → {1, 2, 3, 4, 5}
**/

public static boolean removeDuplicateInts(int[] Numbers) {

// Write your code here
return false;

}

/**
Given a String array, return an String array with duplicate Strings removed if the array contains duplicate values.
Note: Capital letters count

removeDuplicateStrings({"a"}) → {"a"}
removeDuplicateStrings({"a", "b", "c", "d"}) → {"a", "b", "c", "d"}
removeDuplicateStrings({"a", "a"}) → {"a"}
removeDuplicateStrings({"A", "a"}) → {"A", "a"}
removeDuplicateStrings({"these", "are", "the", "times"}) → {"these", "are", "the", "times"}
removeDuplicateStrings({"these", "times", "are", "the", "times", "they", "are"}) → {"these", "times", "are", "the", "they"})

**/

public static boolean removeDuplicateStrings(String[] Strings) {
// Write your code here
return false;

}

/**
Given two int arrays return true if the arrays contain the same values in the same order.
Note: Order matters, see the third example

compare2IntArrays({3, 4}, {1}) → false
compare2IntArrays({1, 2}, {1, 2}) → true
compare2IntArrays({1, 2}, {2, 1}) → false
compare2IntArrays({1, 2, 3, 4}, {1, 2, 3, 4}) → true
**/


public static boolean compare2IntArrays(int[] firstNumbers, int[] secondNumbers) {
// Write your code here
return false;
}

/**
Given two String arrays return true if the arrays contain the same values in the same order.
Note: Order matters, see the forth example
Note: Capatil letters matter, see the final example

compare2StringArrays({"and"}, {"or"}) → false
compare2StringArrays({"and", "but"}, {"or"}) → false
compare2StringArrays({"a", "b", "c", "d"}, {"a", "b", "c", "d"}) → true
compare2StringArrays({"a", "b", "c", "d"}, {"d", "c", "b", "d"}) → false
compare2StringArrays({"a", "b", "c", "d"}, {"A", "b", "C", "d"}) → false
compare2StringArrays({"Aunt", "Sally"}, {"Aunt", "Sally"}) → true
compare2StringArrays({"Aunt", "Sally"}, {"Aunt", "sally"}) → false
**/


public static String[] compare2StringArrays(String[] firstStrings, String[] secondStrings) {
// Write your code here
return new String[]{"0", "0", "0", "0"};

}

Explanation / Answer

import java.util.*;
class RemoveDuplicate
{
public static int[] removeDuplicatesInts(int[] a)
{
  
Arrays.sort(a);
int j = 0;
int i = 1;
if(a.length < 2){
return a;
}
while(i < a.length){
if(a[i] == a[j]){
i++;
}else{
a[++j] = a[i++];
}   
}
int[] output = new int[j+1];
for(int k=0; k<output.length; k++){
output[k] = a[k];
}
return output;
}
public static String[] removeDuplicateStrings(String[] array) {
List<String> noDuplicates = new ArrayList<String>();
for (String arrayElem : array) {
if (!noDuplicates.contains(arrayElem)) {
noDuplicates.add(arrayElem);
}
}
String[] s={""};
return (String[]) noDuplicates.toArray(s);
}
public static boolean compare2IntArrays(int[] firstNumbers, int[] secondNumbers)
{
boolean f=true;
if(secondNumbers.length!=firstNumbers.length) return false;
for(int i=0; i<firstNumbers.length; i++)
{

if(firstNumbers[i]!=secondNumbers[i])
return false;
}
return true;
}
public static boolean compare2StringArrays(String[] firstStrings, String[] secondStrings)
{
if(firstStrings.length!=secondStrings.length) return false;
for(int i=0; i<firstStrings.length; i++)
{

if(!firstStrings[i].equals(secondStrings[i]))
return false;
}
return true;



}

public static void main(String a[])
{
int[] n={7, 7};
int[] d=removeDuplicatesInts(n);

for(int i=0;i<d.length;i++)
System.out.print(d[i]+", ");

String[] s={"these", "times", "are", "the", "times", "they", "are"};
s=removeDuplicateStrings(s);

for(int i=0;i<s.length;i++)
System.out.print(s[i]+" ");

int[]a1={1, 2};
int[]a2={2, 1};
System.out.println(compare2IntArrays(a1,a2));
  
  
String[] s1={"aunty", "sally", "c", "d"};
String[] s2={"aunty", "sally", "c", "d"};
System.out.println(compare2StringArrays(s1,s2));
}
}