Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote