Write a program Distinct that takes an arbitrary number of integer command-line
ID: 3563918 • Letter: W
Question
Write a program Distinct that takes an arbitrary number of integer command-line arguments; it should print true if they all have distinct values, and false otherwise.
For example, your program will print true for the following lists:
18
12 4 25 7 15
98 245 34
And print false for the following lists:
2 4 4 5
98 98
Here is the java code
public class Distinct {
public static void main(String[] args) {
int N = args.length;
// convert each arg and store them in an array of integers
int [ ] values =new int [n] ;
for (int i = 0; i < N ; i ++ )
values = Integer.parseInt(args[i]);
// are all of the pairs examined so far distinct?
boolean result = true;
// we'll examine each values[i] in the array
for (int i = 0; i < N; i++) {
// we'll examine values[j] for each other j
for (int j = 0; i>N ; i ++) {
// are they different or not?
if ( i > j ) {
result =true;
}
}
}
Explanation / Answer
Yes
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.