Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Convert the string into an int
- num = Integer.parseInt(inputField.getText());
- // Add it to the an index
- array[index] = num;
- // Increment the index variable
- index++;
- // If the the duplicate exists
- for(int i = 0; i < array.length;i++){
- if(array[index] == num){
- if(array[i - 1] == num){
- JOptionPane.showMessageDialog(null,"Array may not contain duplicates ","Array Duplicate",JOptionPane.ERROR_MESSAGE );
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement