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
  • 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) {

  • 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 .

  • 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...

  • Write a program that first gets a list of integers from the input and adds them...

    Write a program that first gets a list of integers from the input and adds them to an array. The input begins with an integer indicating the number of integers that follow (Your program should work for any size of the array). Then, get the last value from the input, and output all integers less than or equal to that value by iterating through the array. Ex: If the input is: Enter the number of integers: 5 Enter integer 1:...

  • In Java Implement a program that reads two integers (n and k). The program must output...

    In Java Implement a program that reads two integers (n and k). The program must output the binomial coefficient as follows: Inn! (k)k!(n. - (n k > 0) (1) Also, print every coefficient that is before binomial coefficient for given k; Example: Insert n: 5 Insert k: 3 Result: 10 Coefficient-array: 1 5 10 10

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

  • Change (103) to base 2 in binary number? Question2 outputs) Wr difference, the product, the average,...

    Change (103) to base 2 in binary number? Question2 outputs) Wr difference, the product, the average, the distance (assuming the two entered numbers are x,y coordinates) from the origin, the maximum (the larger of the two integers), the minimum (smaller of the two integers). 2: (section 350; optional for (001/002) (18 points: 4 points for inputs, 2 points for each ite a Java program that accepts two integers from the user and then prints the sum, the Your console output...

  • Write a program that reads a sequence of integers into an array and that computes the...

    Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....

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
ADVERTISEMENT