Monday, 20 May 2013

change void method to return method in oreder to remove duplicates in array [closed]

change void method to return method in oreder to remove duplicates in array [closed]

this my code if any can help to change the void method to return method although this code work properly.
import javax.swing.JOptionPane;
public class duplicateRemover{
     public static void main(String[] args) {
    int[] array = new int[5];
    for (int i=0; i<5;i++) {
      String s=JOptionPane.showInputDialog(null,"PLEASE ENTER AN INTEGER:","INTEGERS",JOptionPane.QUESTION_MESSAGE);
      array[i] = Integer.parseInt(s);
    }
    removeDuplicates (array);
     }
public static void removeDuplicates(int array []) {
  for (int i = 0; i < 5; i++) {
    boolean found = false;
    for (int j = 0; j < i; j++){
      if (array[i] == array[j]) {
        found = true;
        break;
      }
    }
      if (!found){
      JOptionPane.showMessageDialog(null,array[i],"UNIQE INTEGERS",JOptionPane.PLAIN_MESSAGE);
      }

  }
 }
}

No comments:

Post a Comment