Write a java program to sort names in an array?

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024

Комментарии • 18

  • @sushant3530
    @sushant3530 2 года назад +9

    source code:
    String name[]={"BANANA","APPLE","PINEAPPLE","MANGO","KIWI"};
    int n = name.length; //array length=5
    String tmp;
    for(int i=0; i

  • @passionfruit712
    @passionfruit712 Год назад +4

    Why do you creat 2 objects of Scanner can't we just use 1 ?

  • @sarahcharlotte6681
    @sarahcharlotte6681 Год назад +2

    Ur teaching awsome.Subscribed to ur channel bro.

  • @sainath2983
    @sainath2983 5 месяцев назад +1

    public class Program
    {
    static void Main(string[] args)
    {
    string[] str = {"Banana,Grapes,Apple" };
    var splitstring = str.Select(x=> x.Split(",")).ToArray();
    string[] result = splitstring[0].ToArray();
    string temp = string.Empty;
    for(int i =0;i< result.Length; i++)
    {
    for(int j =i +1;j< result.Length; j++)
    {
    if (result[i].CompareTo(result[j]) > 0)
    {
    temp = result[j];
    result[j] = result[i];
    result[i] = temp;
    }
    }
    }
    foreach(var x in result)
    {
    Console.WriteLine(x);
    }
    }
    }

  • @Vijai777
    @Vijai777 2 года назад +1

    Explanation superb...

  • @sushant3530
    @sushant3530 2 года назад +1

    amazing explanation sir

  • @devilox1166
    @devilox1166 Год назад +4

    Why do you create two objects of scanner?

    • @passionfruit712
      @passionfruit712 Год назад

      Same question

    • @madhavkiagya
      @madhavkiagya Год назад +4

      if you do not create a new object, it will take only 2 names in input, i.e. 1st i/p banana and second i/p grapes can be entered but can't enter 3rd i/p apple

  • @balakrishnan-pe9tl
    @balakrishnan-pe9tl Год назад +1

    If I give apple a as small and Banana B as capital and Grapes G as capital means the out put will be
    Banana Grapes apple
    Even if we gave the input in capital also it should come in alphabetical order so pls write a program for that

    • @sharonsam5687
      @sharonsam5687 Год назад

      for(int i=0;i

    • @balakrishnan-pe9tl
      @balakrishnan-pe9tl Год назад

      @@sharonsam5687 hi. This is normal sorting program. If gave names ( Bala ,anbu,Ram ) like this also I want in alphabetically but Its not coming it's coming Bala,Ram,anbu.

    • @medamvinodkumarreddy6478
      @medamvinodkumarreddy6478 11 месяцев назад

      Just do one thing. While sending the name to comapareTo method use toUpperCase() or toLowerCase() methods.

  • @Storyonmountains
    @Storyonmountains Год назад

    Nyc explanation ❤

  • @passionfruit712
    @passionfruit712 Год назад

    Why do you creat 2 objects of Scanner can't we just use 1 ?

  • @passionfruit712
    @passionfruit712 Год назад +1

    Why do you creat 2 objects of Scanner can't we just use 1 ?