Question

In: Computer Science

problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following...

problem 1 (Duplicate Elimination) code in JAVA please

Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of -1 for all elements. Assume a value of -1 indicates an array element is empty. You are then to process the array, and remove duplicate elements from the array containing the numbers you input. Display the contents of the array to demonstrate that the duplicate input values were actually removed.

Sample Output could be as follows:

Sample 1:

Please input a value in [10,100]

value 1: 78

value 2: 34

value 3: 46

value 4: 74

value 5: 87

value 6: 39

value 7: 39

value 8: 46

value 9: 78

value 10: 78

The unique values are:

78 34 46 74 87 39

Solutions

Expert Solution

The code in java is given below.

import java.util.Scanner;
import static javafx.application.Platform.exit;

public class duplicateElimination
{
    public static void main(String[] args)
    {
        int[] arr=new int[10];
        for(int i=0;i<10;i++)
        {
            arr[i]=-1;
        }
        System.out.println("Please input a value in [10,100]");
        Scanner sc=new Scanner(System.in);
        int value;
        for(int i=0;i<10;i++)
        {
            System.out.print("value "+(i+1)+": ");
            value=sc.nextInt();
            if(value<10 || value>100)
            { System.out.println("Value should be in [10,100]");
                i=i-1;
                continue;
            }
            arr[i]=value;
        }
        System.out.println("The unique values are: ");
        int newLength=arr.length;
        for(int i=0;i<newLength;i++)
        {
            for(int j=i+1;j<newLength;j++)
            {
                if(arr[i]==arr[j])
                {
                    arr[j]=arr[newLength-1];
                    newLength--;
                    j--;
                }
            }
        }
        for(int i=0;i<newLength;i++)
        {
            System.out.print(arr[i]+" ");
        }

    }
}




The screenshot of the running code and output is given below.










If the answer helped please upvote it means a lot. For any query please comment.

Related Solutions

(duplicate Elimination) use a one-dimensional array to slove the following program. read 20 numbers, each of...
(duplicate Elimination) use a one-dimensional array to slove the following program. read 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print if only if its not a duplicate of a number already read. Provide for the "worst case" in which all 20 numbers are different. Use the smallest possible array to slove this problem. sort the array in ascending order and print the elements of the sorted array. This much be done...
In JAVA Use a two-dimensional array to solve the following problem: A company has four salespeople...
In JAVA Use a two-dimensional array to solve the following problem: A company has four salespeople - Sales Person 1, Sales Person 2, Sales Person 3, and Sales Person 4. The company sells 5 products - Product 1, Product 2, Product 3, Product 4, and Product 5. Each day, a sales person hands in a slip with the following information: Sales Person Number (1,2,3, or 4), Product Number (1,2,3,4, or 5), and dollar value of that product sold. This dollar...
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem. Your solution must include a function called isUnique() that returns 1 (true) if the number input is...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
1.Write the java code to create a two dimensional String array of sizes 12 by 8;...
1.Write the java code to create a two dimensional String array of sizes 12 by 8; Given the java array:       double[] test = new double[3]; 2.  Write the java code to put the numbers 1.0, 2.0, and 3.0 in to the array so that the 1.0 goes in the first cell, the 2.0 goes in the second cell and the 3.0 goes in the third cell. 3. Can you have different types of data is a three dimensional array? 4....
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT