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

Need a java program that outputs this: Use a loop to detect the repeat character

ID: 3823611 • Letter: N

Question

Need a java program that outputs this:

Use a loop to detect the repeat characters and another lopp to create the revised array with no repeat characters.

The method should be called deleteRepeats

Example 1 original array values a,b, c, Revised array values after repeats removed: a, b, c, Example 2 original array values: a,b, c, c, Revised array values after repeats removed: a,b,c, Example 3 Original array values a, a,b, Revised array values after repeats removed: a,b, Example 4 original array values: b, a, a, Revised array values after repeats removed: b, a, Example original array values: c,c, c, d, Revised array values after repeats removed: c, d, Example 6 Original array values a,b, a, e, a, a,c, d, e,e, Revised array values after repeats r a, b, c, d, e Example 7 original array values a, a, b, b,b, c,d, Revised array values after repeats removed: a, b, c,d BUILD SUCCESSFUL (total time: 0 seconds)

Explanation / Answer

code:

import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;
import java.util.List;

class DeleteDups{

public static void main (String[] args)
{
  
   Scanner scanner = new Scanner(System.in);
   System.out.println("Original Array values:");
String Originals=scanner.nextLine();
   String Output = Deleterepeats(Originals);
     
   System.out.println("Revised Array values:"+Output);  
  
  
}

public static String Deleterepeats(String s)
{
   String[] InputArray = StringtoArray(s);
   removeDuplicates(InputArray);

   StringBuilder sb = new StringBuilder();
   for (String n : InputArray) {
       if (sb.length() > 0) sb.append(',');
       sb.append("'").append(n).append("'");
       }
  
   return sb.toString();
  
}

private static String[] StringtoArray(String str){
String[] splittArray = null;
if (str != null || !str.equalsIgnoreCase("")){
splittArray = str.split(",");
System.out.println(str + " " + splittArray);
}
return splittArray;
}

public static int removeDuplicates(String[] A) {
int length=A.length;
if(length==0 || length==1) return length;
int i=1;
for(int j=1; j<length; j++){
if(!A[j].equals(A[j-1])){
A[i]=A[j];
i++;
}
}
if(i<length) A[i]=null;
return i;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote