import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws
java.lang.Exception
{
Scanner sc= new
Scanner(System.in);
System.out.println("Enter number of
elements of array:- ");
num=sc.nextInt();
int[] numbers = new int[num];
for(int i=0;i<num;i++){
numbers[i]=sc.nextInt();
}
List<Integer> isolate = new ArrayList<Integer>();
Boolean dupliceExists;
for (int i = 0; i < numbers.length; i++) {
dupliceExists = Boolean.FALSE;
for (Integer integ : isolate) {
if (Integer.valueOf(numbers[i]).equals(integ)) {
dupliceExists = Boolean.TRUE;
//Get index if you need the index of duplicate from here
}
}
if (!dupliceExists) {
isolate.add(numbers[i]);
}
}
Collections.sort(isolate);
for (int i = 0; i < isolate.size(); i++) {
System.out.println(isolate.get(i));
}
}
}
here i have created a class in which i am entering the number of elements in array from user (you can enter 1000)
then input the elements of array. then we just find whether the element occurs earlier in the array or not. If it finds in the array and maintains that via boolean variable.
then just added the element in list of interger type and applied the Collections.sort to sort the elements of second array. finally prints them.
Write a program that asks the user to enter 1000 integers to be stored in an...
Write a program in JAVA that asks the user to enter an integer. Store the integers in an array. Allow for up to 10 integers. When the user enters -1, the program should end. Print the number of integers entered as well as the number of times each integer was entered.
Write a program that will create an array of ten integers, allow the user to enter those integers, and eventually search through the array based on index position: 1. Declare the array. You cannot assign elements to an array until it has first been created. 2. Next, run a for loop so that the user can enter an integer to save in each index position of the array. Since you this array holds ten elements , the index position starts...
write a program that asks the user to enter two integers one at a time if the first value is not an integer then do not ask for a second then display both values otherwise print error message stating which value entered was not an integer python
Write a program that asks the user how many integers they would like to enter. You can assume they will enter an integer >= 1. The program will then prompt the user to enter that many integers. After all the numbers have been entered, the program should display the largest and smallest of those numbers (no, you cannot use lists, or any other material we haven't covered). When you run your program it should match the following format: How many...
Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...
Write a python program that repeatedly asks the user to input a pair of integers. The program should record the largest number of each pair into a list. The program should keep asking the user to input pairs of numbers until the user enters -1 for the first number. At this point the program should print the list on a single line, with each value separated by a space and then stop. Example of expected behaviour: Please enter first number:...
Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...
Write a multithreaded sorting program that works as follows: A
list of integers
is divided into two smaller lists of equal size. Two separate
threads (which we
will term sorting threads) sort each sublist using a sorting
algorithm of your
choice. The two sublists are then merged by a third thread—a
merging thread
—which merges the two sublists into a single sorted
list.
Because global data are shared cross all threads, perhaps the
easiest way
to set up the data...
LANGUAGE: JAVA
Sorting an array: 2. Write a program that asks the user for 5 numbers and stores them in an array called data. Then call a method that accepts the array as an argument, sorts the array in ascending order and prints out the original AND sorted array (Hint: The method does not return anything in this case, so it should be set to void).
Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...