Question: Task 2 ( Number of different ( sorted ) ) Create the method public static int numberUnlikeSorted ( int [ ] a ) . If

Task 2(Number of different (sorted))
Create the method public static int numberUnlikeSorted(int[] a). If the table a is not sorted in ascending
order, the method must throw an IllegalStateException with the appropriate text. If a is sorted in ascending
order, the method must output how many different numbers are in the table.
The table a can have the same values, or can only have different values. If, for example, we have int[]
a={3,3,4,5,5,6,7,7,7,8}, the method should return 6, since there are 6 different values in the table.
The method must not change the table's content. The method must return 0 if the table is empty. An
empty table should not give an error message.
Task 3(Number of different (unsorted))
Create the method public static int numberUnsorted(int[] a). The table a can now be any integer table, it
does not have to be sorted, and can have several equal values.
The method should return how many different values are in a, and should not
change the table's contents.
The method should not use any auxiliary tables. All work must only take place
within the table a. You cannot, for example, create a sorted copy of a, or create a
table of previously recorded values. You can of course create auxiliary variables.
Exercise 4(Part sorting)
Create the method public static void partsorting(int[] a). It should split the table a into two sorted parts.
The left part must contain all the odd numbers sorted, and the right part all the even numbers sorted. The
following example shows the area of use:
int[]a={6,10,9,4,1,3,8,5,2,7}; subsort(a); // Now we should
have ,
4,6,8,10.
The table a can be empty, can contain both negative and positive numbers, can consist of
only odd numbers, or only of only even numbers. None of these possibilities should give an
error message.
The method must not use auxiliary tables. All work must only take place inside
table a. You can of course use auxiliary variables.
The method must be designed so that it is relatively effective. One of the tests will measure efficiency
on large tables.
Task 2 ( Number of different ( sorted ) ) Create

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!