Computer Science, asked by neelndesai, 10 months ago

Write a program to input 50 names along with their weights in an array and sort the names in alphabetical order using selection sort technique.

in java only

spam answer will be reported

Answers

Answered by itzpihu07
1

TO KAISE H AAP LOG

Answer:

hey mate here's ur answer

Explanation:

import java.util.Scanner;

public class Alphabetical_Order

{

public static void main(String[] args)

{

int n;

String temp;

Scanner s = new Scanner(System.in);

System.out.print("Enter number of names you want to enter:");

n = s.nextInt();

String names[] = new String[n];

Scanner s1 = new Scanner(System.in);

System.out.println("Enter all the names:");

for(int i = 0; i < n; i++)

{

names[i] = s1.nextLine();

}

for (int i = 0; i < n; i++)

{

for (int j = i + 1; j < n; j++)

{

if (names[i].compareTo(names[j])>0)

{

temp = names[i];

names[i] = names[j];

names[j] = temp;

}

}

}

System.out.print("Names in Sorted Order:");

for (int i = 0; i < n - 1; i++)

{

System.out.print(names[i] + ",");

}

System.out.print(names[n - 1]);

}

}

$ javac Alphabetical_Order.java $ java Alphabetical_Order   Enter number of names you want to enter:5 Enter all the names: bryan adam rock chris scott Names in Sorted Order:adam,bryan,chris,rock,scott0

MARK AS BRAINLIST ANSWER

follow me

Answered by harnathyadav2907
0

Explanation:

// Java program for implementation of Selection Sort

class SelectionSort

{

void sort(int arr[])

{

int n = arr.length;

// One by one move boundary of unsorted subarray

for (int i = 0; i < n-1; i++)

{

// Find the minimum element in unsorted array

int min_idx = i;

for (int j = i+1; j < n; j++)

if (arr[j] < arr[min_idx])

min_idx = j;

// Swap the found minimum element with the first

// element

int temp = arr[min_idx];

arr[min_idx] = arr[i];

arr[i] = temp;

}

}

Similar questions