What is the mistake in the program. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

What is the mistake in the program.

I had written a program to find the name smallest by alphabatical order.But I don't understand what is the problem in the program https://code.sololearn.com/cpJ2RTq3wvJv/?ref=app

6th Jul 2020, 3:55 PM
Akash
Akash - avatar
5 ответов
+ 1
First of all I would recommend a structure for the code. The first part names in alphabetical order looks like: import java.util.Scanner; import java.util.Arrays; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String me = sc.nextLine(); int agents = Integer.parseInt(sc.nextLine()); String people = me + " " + sc.nextLine(); String names[] = people.split(" "); Arrays.sort(names); for(int i=0; i<names.length; i++) System.out.println(names[i]); System.out.println(agents); } }
6th Jul 2020, 5:30 PM
JaScript
JaScript - avatar
+ 3
You have a string array names. Inside the loops you want to create a String nlc = name[i].toLowerCase(); I guess it should be names[i] In Line 32 you have a typo: lengtb
6th Jul 2020, 4:09 PM
Denise Roßberg
Denise Roßberg - avatar
+ 3
What is the mistake in this 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:30 PM
Akash
Akash - avatar
+ 2
The statements shall be: .... String nlc = names[i].toLowerCase(); .... String nlc1 = names[j].toLowerCase(); ..... for(y=0;y<al.length;++y)
6th Jul 2020, 4:07 PM
JaScript
JaScript - avatar
+ 1
Akash Line 32 but as I can see you already changed it.
6th Jul 2020, 4:15 PM
Denise Roßberg
Denise Roßberg - avatar