+ 3

What is the mistake in the Code.

Why program is not printing all names in alphabatical order.How I can Solve it.I am doing it for Code Coach New Driver's Liscense Challenge.Please help me I am trying to do it from 2 days. https://code.sololearn.com/c6Iby2g42irJ/?ref=app

6th Jul 2020, 4:21 PM
Akash Sharma
Akash Sharma - avatar
2 Answers
+ 1
1) read your name in a variable (String me). 2) read the number of agents in a variable (int ag) 3) read the names of other people (String people) 4) concatenate (add) your name to the people. 5) split people to an array String [] names. 6) sort the array names i.e. java.util.Arrays.sort(names); and then the logic for the solution solution (in C#): for(int i = 0; i<names.Length; i++){ if(names[i]==me){ if((i+1)%ag==0){ Console.Write((i+1)/ag*20); } else { Console.Write((i+1)/ag*20+20); } } }
6th Jul 2020, 4:58 PM
JaScript
JaScript - avatar
+ 1
An example for waiting looks like: for(int i=0; i<names.length; i++){ //System.out.println(names[i]); //System.out.println(agents); if(names[i].equals(me)){ if((i+1) % agents == 0){ System.out.print((i+1)/agents*20); } else { System.out.print((i+1)/agents*20+20); } } }
6th Jul 2020, 6:48 PM
JaScript
JaScript - avatar