Answer to Question #264675 in Java | JSP | JSF for Marwa

Question #264675

Write a Java program that creates an Array of string values and displays the duplicate values.


1
Expert's answer
2021-11-12T00:09:00-0500
public class Main {
    public static void main(String[] args) {
        String[] array = {"Five","One", "Two", "Three", "One", "Three", "Five", "One"};
        for (int i = 0; i < array.length; i++) {
            boolean shown = false;
            for (int j = i - 1; j >= 0; j--) {
                if (array[j].equals(array[i])) {
                    shown = true;
                    break;
                }
            }
            for (int j = i + 1; j < array.length && !shown; j++) {
                if (array[j].equals(array[i])) {
                    System.out.println(array[i]);
                    break;
                }
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS