Java program to sort a given list of names in ascending order

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class sorting
{
	public static void main(String[] input)
	{
		int k=input.length;
		String temp=new String();
		String names[]=new String[k+1];
		for(int i=0;i<k;i++)
		{
			names[i]=input[i];
		}
		for(int i=0;i<k;i++)
			for(int j=i+1;j<k;j++)
			{
				if(names[i].compareTo(names[j])<0)
				{
					temp=names[i];
					names[i]=names[j];
					names[j]=temp;
				}
			}
System.out.println(“Sorted order is”);
for(int i=0;i<k;i++)
{
			System.out.println(names[i]);
}
     }
}

Output:

Java sorting Harish Ramesh Mahesh Rakesh
Sorted order is
Ramesh
Rakesh
Mahesh
Harish

Java sorting sai hari teja ravi sandeep
Sorted order is
teja
sandeep
sai
ravi
hari

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

29 thoughts on “Java program to sort a given list of names in ascending order

  1. Acne products are no longer just face scrubs, washes, acne creams, acne facial care and the like but now include foundation and other cosmetic products. No longer do users have to apply acne medicine before they apply foundation. That doesn’t mean that all foundation includes acne products in their ingredients, so you will need to find out when you are ready to purchase acne products. So the advantage of MBT shoes you will know. Above all, MBT shoes really do rate above Shape Ups. Now Shape Ups are still very good shoes. Jets Jersey

  2. plss!!!!! give come comment inside the program so it can be easily to understand for begginers ya~ha!

  3. However, not only this but if yyou to go a step above and have one completely customized home ffor you, then you must think about a Texas Custom Home Builder.You arre also enticing more buyers too your house if eventually you decide to
    sell it. These types of cabinets tend to separate,
    split or warp over longer periods of times whereas kitchen cabinets with cam-lock systems or metal
    brackets orr clips offer a more dependable cabinet.

  4. package com.imatrix;
    import java.util.*;
    public class ArrayEx {
    int i=0;
    String temp=””;
    String[] stringArray;

    public void string() throws Exception
    {
    Scanner stringS = new Scanner(System.in);
    System.out.println(“How Many Number you Want to Enter”);
    i = stringS.nextInt();
    stringArray=new String[i];

    for(int i=0;i”);
    Scanner integer2 = new Scanner(System.in);
    stringArray[i]=integer2.nextLine();
    }
    for(int i=0;i<stringArray.length;i++)
    {
    for(int j=i+1;j0)
    {
    temp=stringArray[i];
    stringArray[i]=stringArray[j];
    stringArray[j]=temp;
    }
    }
    }
    System.out.println(“Sorted order is”);

    for(int j=0;j<stringArray.length;j++)
    {
    System.out.println(stringArray[j]);
    }
    }

    public static void main(String[] args) throws Exception
    {
    ArrayEx objArrayEx=new ArrayEx();
    objArrayEx.string();

    }
    }

  5. package com.imatrix;
    import java.util.*;
    public class NameAscending{
    int i=0;
    String temp=””;
    String[] stringArray;

    public void string() throws Exception
    {
    Scanner stringS = new Scanner(System.in);
    System.out.println(“How Many Number you Want to Enter”);
    i = stringS.nextInt();
    stringArray=new String[i];

    for(int i=0;i”);
    Scanner integer2 = new Scanner(System.in);
    stringArray[i]=integer2.nextLine();
    }
    for(int i=0;i<stringArray.length;i++)
    {
    for(int j=i+1;j0)
    {
    temp=stringArray[i];
    stringArray[i]=stringArray[j];
    stringArray[j]=temp;
    }
    }
    }
    System.out.println(“Sorted order is”);

    for(int j=0;j<stringArray.length;j++)
    {
    System.out.println(stringArray[j]);
    }
    }

    public static void main(String[] args) throws Exception
    {
    NameAscending objArrayEx=new NameAscending();
    objArrayEx.string();

    }
    }

  6. A Department of Defense study found that nearly 70% oof junilr military members
    who had taken out military auto loans in the past year had been the victim to some form of unethical lender or dealer tactics.
    If the police aree called, chargs may be ade against
    both the parties. Keep in mind, taxes ddo not need to be due
    noor does the transaction have to be proven illegal or illegitimate ffor this penalty to apply.

  7. A commercial pressure washer is employed for
    selection of purpose with a daily basis for many cleaning tasks.
    As tagged by NASA’s Glenn Research Center, the middle of gravity is “the average location from the weight with the object.
    If you don’t desire to completely depend upon drying sensors, then you definitely should make certain your dryer has timer settings on it. However, there is much more occurring inside of this “machine” than merely wetting and rinsing your clothing.

  8. The significance of toys in today’s world is no less than a unique plaything just for fun and enjoyable means of
    the young life in human society. Kids can learn that
    the cycle toy is used not simply for driving but also for keeping body and mind healthy
    and fit. Nerf video game With younger children, you don’t have to spend
    a good deal of money with regards to buying childrens
    toys, they’ll be pleased with almost anything since the globe is pretty new to them.

    If the markings are removed, policemen can mistake a toy gun for
    the real gun. They give a wide range of age-specific brands to choose
    from including safe and quality wooden toys.

  9. The body will defer to its normal habits and patterns of
    movement. Plantar Fasciitis – For these that have questioned wht iss Plantar Fasciitis,
    the response may well be surprising. The processs has
    a few seconds annd is also very painful.

  10. In case the array is compose of arrays of different data type, here is go about if. I hope it will you
    ================================================================================================================

    package exercise4_test;
    import java.util.Scanner;
    /**
    *
    * @author Tangeni Kamati
    */
    public class Exercise4_Test {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    Scanner kbd=new Scanner(System.in);
    String stName;
    int test1Marks;
    int test2Marks;
    int test3Marks;
    double ave;
    /*Student[] std;
    std = new Student(stName,test1Marks,test2Marks,test3Marks,ave);*/
    Student[] std;
    std = new Student[3];

    for(int r=0;r<std.length;r++){
    System.out.println("Enter the name :");
    stName=kbd.nextLine();
    System.out.println("Enter marks for test 1:");
    test1Marks=kbd.nextInt();
    System.out.println("Enter marks for test 2:");
    test2Marks=kbd.nextInt();
    System.out.println("Enter marks for test 3:");
    test3Marks=kbd.nextInt();
    String kk=kbd.nextLine();
    ave=(test1Marks+test2Marks+test3Marks)/3;
    std[r]=new Student(stName,test1Marks,test2Marks,test3Marks,ave);
    }
    System.out.println("Enter the name to to see if is in the list:");
    String EnteredName=kbd.nextLine();
    String NameFound="";
    for(int f=0;f<std.length;f++){

    if((std[f].getName().equals(EnteredName))){
    System.out.println("The name "+std[f].getName()+" was found.\nTest 1: "+std[f].getTest1()+"\nTest 2: "+std[f].getTest2()+"\nTest 3: "+std[f].getTest3()+"\nAverage: "+std[f].getAverage());
    NameFound="";
    break;
    }
    else{
    NameFound="Name not found.";
    }
    }
    System.out.println(NameFound);
    Student inst=new Student();

    for(int k=0;k<std.length;k++){

    for(int l=k+1;l<std.length;l++){
    if(std[l].getName().compareToIgnoreCase(std[k].getName())<0){
    inst=std[k];
    std[k]=(std[l]);
    std[l]= inst;

    }
    }
    }
    for(int p=0;p<std.length;p++){
    std[p].toString();
    }
    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in