Question

A.) Write a Java Θ(nlogn) program that outputs all unique integers in the provided array. Output...

A.) Write a Java Θ(nlogn) program that outputs all unique integers in the provided array. Output integers must be unique, meaning non-repetative (eg. 4, 2, 6, 3, 5, 1, 7).

{4, 2, 6, 4, 3, 5, 5, 6, 6, 1, 7}

B.) Provide a detailed description of the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

import java.io.*;
public class ArrayDistinct {
public static void printDistinct(int[] array)
{
for(int i=0;i<array.length;i++){ // Here we are using for loop to to read array length
boolean isUnique = false; // Here we are taking variable called isUnique as a boolean varaible
for(int j=0;j<i;j++){
if(array[i] == array[j]){

// Here we are comparing the each value in the array if it is equal then it Ignore the value
isUnique = true;

// Here if the above condition is satisfied it Ignore the value and come out of the loop
break;
}
}
if(!isUnique){ // Here if the above condition fails then it prints that array value
System.out.print(array[i]+" ");
}
}
} // End of  printDistinct() method
public static void main(String args[])
{
int[] num = {4, 2, 6, 4, 3, 5, 5, 6, 6, 1, 7};// Here we are taking array of elements
ArrayDistinct.printDistinct(num); // calling the printDistinct() method here
}
}
     
Output:

.Administrator: Windows Command Processor F:javajavac ArrayDistinct.java Fjava java ArrayDistinct 4 2 6 3 51 7

Add a comment
Know the answer?
Add Answer to:
A.) Write a Java Θ(nlogn) program that outputs all unique integers in the provided array. Output...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [C++] Write a program that reads a list of integers, and outputs those integers in reverse....

    [C++] Write a program that reads a list of integers, and outputs those integers in reverse. You must use an array for this lab. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Ex: If the input is: 5 2 4 6 8 10 the output is: 10 8 6 4 2 5 To achieve the above, first read the integers into...

  • JAVA Write a program that shows the contents of the array integers 5 7 4 9...

    JAVA Write a program that shows the contents of the array integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting the array into ascending order. Please provide code in text and snapshot of the program running. thanks!

  • Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array...

    Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array of 100 integers. Initialize the array to have all zeros. 2. Puts even numbers starting from 6 (excluding multiples of 12) into the first 50 slots of the array above. So numbers 6,8,10,14,16,18,20,22,26, etc. go into the first 50 positions in the array. Print the array. 3. Puts random numbers between 45 and 55 into the second 50 slots of the array above (second...

  • Please write a Java program: Given an array of positive integers, return a count of the...

    Please write a Java program: Given an array of positive integers, return a count of the number of even integers. countEvens([2, 3, 5])-1 countEvens([4, 20]) - 2 countEvens([3, 7, 1, 11]) 0 Go Save, Compile, Run (ctrl-enter) int countEvens (int[] nums) {

  • (JAVA) Given an array of unique positive integers, write a function findSums that takes the array...

    (JAVA) Given an array of unique positive integers, write a function findSums that takes the array input and: 1. Creates a hashtable called “hashT” and inserts all the elements of the input array in the hashtable. 2. Finds pairs of elements in the hashtable whose sum is another element (sum) in the hashtable and print the pairs in the console. 3. Returns another hashtable names “sums” of those sum elements. For example: Input: [1,5,4,6,7,9] Output: [6,5,7,9] Explanation: 6 = 1...

  • Write a Java program that allows the following: 1.Create an array list of 20 integers. The...

    Write a Java program that allows the following: 1.Create an array list of 20 integers. The 20 integers are generated randomly with possible values from 0 to 10. 2.Print the content of the array list. 3.Find how many of these values are multiple of 3. Show a screenshot of the output with your name and Id in the first line (if there is no screenshot of the output, the student shall get a zero mark for this question). Program typical...

  • Write a Java program that reads 10 integers from the keyboard and outputs all the pairs...

    Write a Java program that reads 10 integers from the keyboard and outputs all the pairs whose sum is 30 .

  • In JAVA: Write a method that reverses the array passed the argument and returns this array....

    In JAVA: Write a method that reverses the array passed the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers and display the numbers. Write a method that returns a new array by eliminating the duplicate values in the array using following method header: a. Public static int[] eliminateDuplicates(int list) b. Write a test program that reads in ten integers and invoke the method, the...

  • Must use Array. Must be in JAVA. Write a program that uses a Scanner object to...

    Must use Array. Must be in JAVA. Write a program that uses a Scanner object to read in a sequence of integers. The first number in the sequence represents the number of integers in the sequence (i.e., do NOT include the first number as part of the sequence). Create an array of integers that is the same size as the number of integers. Then the program will read each integer and place it in the array. Print the content of...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT