A group of friends have decided to start a secret society. The name will be the first letter of each of their names, sorted in alphabetical order.
Create a function that takes in an array of names and returns the name of the secret society.
societyName(["Adam", "Sarah", "Malcolm"]) ➞ "AMS"
societyName(["Harry", "Newt", "Luna", "Cho"]) ➞ "CHLN"
societyName(["Phoebe", "Chandler", "Rachel", "Ross", "Monica", "Joey"]) ➞ "CJMPRR"
The secret society’s name should be entirely uppercased.
There are some errors in the solution which needs to be rectified
But as @Peter has wrote:
Names are in array which is also a kind of list.
you will receive a list and have to do further process.
So in for loop directly use names list/array.
I have JAVA code so if anyone wants to convert it to blocks then,
Scanner s = new Scanner(System.in);
System.out.print("Enter number of names you want to enter:");
n = s.nextInt();
String names = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter all the names:");
for(int i = 0; i < n; i++)
names[i] = s1.nextLine();
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
temp = names[i];
names[i] = names[j];
names[j] = temp;
System.out.print("Names in Sorted Order:");
for (int i = 0; i < n - 1; i++)
System.out.print(names[i] + ",");
System.out.print(names[n - 1]);