Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Duplicate{
- public static boolean readDataAndDuplicate(int[] x){
- Scanner input = new Scanner(System.in);
- int i;
- System.out.print("Enter from 1 up to " + x.length + " integers; ");
- System.out.println("end with -999");
- for (i = 0; i < x.length; i++){
- System.out.print("Enter next integer value: ");
- x[i] = input.nextInt();
- if (x[i] == -999) break;
- }
- if (i == 0){
- System.out.println("Error: you must enter at least 1 element");
- System.exit(0);
- }
- boolean duplicates=false;
- for (int j=0;j<x.length;j++)
- for (int k=0;k<x.length;k++)
- if (x[k]==x[j]){
- duplicates=true;
- }
- return false;
- public static void main(String[] args){
- readDataAndDuplicate()
- }
- }
- }
Add Comment
Please, Sign In to add comment