Home > Back-end >  Java a great god for help
Java a great god for help

Time:03-19

Package T1;

/*
* 1, consider elements and uniqueness problem: given A collection of integers that assumes A stored in the integer array [1.. n], determine
Of them if there are two equal elements, please design a effective algorithm to solve this problem, your algorithm of time
How much is the complexity?

The specific requirements
The first line of the input: input is a positive integer m, says the number of test cases, the next few lines is m a number of test cases
According to the data of each test case consists of two lines, the first act a positive integer n (n<=500), said an integer sequence
Presented in this paper, the second line of the length of the integer sequences, integers separated with a space between,
Output: the output one line for each test case, test case, if the group two equal output element is Yes, otherwise,
No output, the output of each test case data in one line,
*/

import java.util.Scanner;
Public class T1 {
Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);
System. The out. Println (" please enter the testing use cases: ");
Int m=sc nextInt ();
for(int i=0; iSystem. The out. Println (" please input array contains yuan prime: ");
int n=sc.nextInt();
GetMessage a=new getMessage (n);
System. The out. Println (" please input array element in order and separated by Spaces: ");
Anderson nputArgs (n);
System. The out. Println (" find whether have the same elements: "+ a.s earch ());
System.out.println();
}
sc.close();
}
}

The class getMessage {
Private int n;
Private int the args []=new int [n].
Public getMessage (int n) {
This. N=n;
}
Public void inputArgs (int n) {
Int the args []=new int [n].
Scanner sc=new Scanner(System.in);
for(int i=0; iThe args [I]=sc. NextInt ();
}
sc.close();
Enclosing the args=args.
}
Public void printArgs () {
for (int i=0; iSystem. The out. Print (enclosing the args [I] + "");
}
}
Public Boolean search () {
for(int i=0; iFor (int j=I + 1; jIf (this. The args==this. [I] args [j]) {
return true;
}
}
}
return false;
}
}


Why this code can only be performed for the first time, later can perform?
  • Related