I still fail test case 4 in New Driver's License,why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I still fail test case 4 in New Driver's License,why?

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String me=sc.nextLine(); int agent=sc.nextInt(); String pe=sc.next(); ArrayList<String>people=new ArrayList<String>(5); for(int i=1;i<=4;i++){ people.add(pe); } people.add(me); Collections.sort(people); int myturn=people.indexOf(me); int res=(myturn/agent)*20+20; System.out.println(res); } }

6th Oct 2022, 7:10 AM
Killiam Chances
Killiam Chances - avatar
3 Answers
+ 1
I can't thank you enough for your response. I found what's wrong.
6th Oct 2022, 1:14 PM
Killiam Chances
Killiam Chances - avatar
0
If it is from SL code coach, I think 3rd input contains 4 words separated by space. First input is singles word.. So swap those way of taking input. Either take pe = sc.next() ; inside loop before adding to list.
6th Oct 2022, 11:39 AM
Jayakrishna 🇮🇳
0
Side comment: use more descriptive names for variables, methods, etc. You will thank yourself when making changes some time later or writing more complex code.
7th Oct 2022, 1:39 AM
Emerson Prado
Emerson Prado - avatar