write a program in java to accept the character in an array and sort them according to the alphabetical order with their ASCII value.
Don't spam you will be reported.
Give correct answer or else leave the question.
Share
write a program in java to accept the character in an array and sort them according to the alphabetical order with their ASCII value.
Don't spam you will be reported.
Give correct answer or else leave the question.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Explanation:
Input: arr[] = {‘a’, ‘b’, ‘c’, ‘e’}, M = 2
Output: b a c e
The ASCII % M for the array are
{97 % 2, 98 % 2, 99 % 2, 101 % 2} i.e. {1, 0, 1, 1}
Input: arr[] = {‘g’, ‘e’, ‘e’, ‘k’, ‘s’}, M = 8
Output: k s e e g
Answer:
Given an array arr[] of characters and an integer M, the task is to sort the array based on ASCII % M i.e. the character whose ASCII value % M is minimum should appear first.
Examples:
Input: arr[] = {‘a’, ‘b’, ‘c’, ‘e’}, M = 2
Output: b a c e
The ASCII % M for the array are
{97 % 2, 98 % 2, 99 % 2, 101 % 2} i.e. {1, 0, 1, 1}
Input: arr[] = {‘g’, ‘e’, ‘e’, ‘k’, ‘s’}, M = 8
Output: k s e e g