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

7/6/2020 3:55:47 PM

Akash

5 Answers

New Answer

+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); } }

+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

+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

+2

The statements shall be: .... String nlc = names[i].toLowerCase(); .... String nlc1 = names[j].toLowerCase(); ..... for(y=0;y<al.length;++y)

+1

Akash Line 32 but as I can see you already changed it.