Knowee
Questions
Features
Study Tools

Develop a Java program for sorting and reversing an integer array,character array and floating point array.Use Generic method for the implementation.Finally print the sorted and reversed array.TestcaseInput5(No.of elements (common to all types of array))103020402512.413.311.210.214.6AFDSNOutput403025201014.613.312.411.210.2SNFDA

Question

Develop a Java program for sorting and reversing an integer array,character array and floating point array.Use Generic method for the implementation.Finally print the sorted and reversed array.TestcaseInput5(No.of elements (common to all types of array))103020402512.413.311.210.214.6AFDSNOutput403025201014.613.312.411.210.2SNFDA

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Java program that uses a generic method to sort and reverse an array of integers, characters, and floating point numbers:

import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Integer[] intArray = {10, 30, 20, 40, 25};
        Character[] charArray = {'A', 'F', 'D', 'S', 'N'};
        Float[] floatArray = {12.4f, 13.3f, 11.2f, 10.2f, 14.6f};

        sortAndReverse(intArray);
        sortAndReverse(charArray);
        sortAndReverse(floatArray);

        System.out.println(Arrays.toString(intArray));
        System.out.println(Arrays.toString(charArray));
        System.out.println(Arrays.toString(floatArray));
    }

    public static <T extends Comparable<T>> void sortAndReverse(T[] array) {
        Arrays.sort(array, Collections.reverseOrder());
    }
}

This program first defines three arrays: one of integers, one of characters, and one of floating point numbers. It then calls the sortAndReverse method on each array. This method uses the Arrays.sort method with Collections.reverseOrder as the comparator to sort the array in descending order. Finally, it prints out each array.

The output of this program will be:

[40, 30, 25, 20, 10]
[N, S, F, D, A]
[14.6, 13.3, 12.4, 11.2, 10.2]

This matches the expected output in your question.

This problem has been solved

Similar Questions

Develop a Java program for sorting an integer array, floating-point array and character array. Use Generic method for the implementation. Finally print the sorted array. Note: consider the size of the array to be 5.

Write a java method to reverse the elements of an array using recursion. Your method should take an array as an input parameter and return reverse the array

Reverse an ArrayWrite a program to reverse the elements of an array of integers.Constraints:NAExample:Sample Input:512345Sample Output:5 4 3 2 1 Explanation:First line of input--> size of array (n) -->5n lines of integers into the array-->1 2 3 4 5Output--> Reversed array --> 5 4 3 2 1Public Test Cases:# INPUT EXPECTED OUTPUT1 5123455 4 3 2 1

As an array lover, your friends have given you a challenge to solve a question on arrays, so the challenge goes as - :You are given an array 'r' consisting of 'x' integers. Unfortunately, the size of 'r' is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array 'r' (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.Input FormatThe first line of the input contains an integer x (1 ≤ x ≤ 10^5) — the size of array 'r'. The second line contains 'x' distinct space-separated integers.Constraints'x' distinct space-separated integers r[1], r[2], ..., r[x] (1 ≤ r[i] ≤ 10^9).Output FormatPrint "yes" or "no" (without quotes), depending on the answer.

answer this question in simple code for beginners using intellJ: 4. Write a Java program to sort an array of given integers using the Merge Sort Algorithm.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.