0% found this document useful (0 votes)
7 views3 pages

Java Program for Sorting Arrays

The document contains a Java program that implements sorting algorithms for both integers and strings. It allows users to choose between sorting an array of integers or a predefined array of strings, displaying the sorted results. The program runs in a loop, prompting the user to continue or exit after each sorting operation.

Uploaded by

Manoj Avhad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Program for Sorting Arrays

The document contains a Java program that implements sorting algorithms for both integers and strings. It allows users to choose between sorting an array of integers or a predefined array of strings, displaying the sorted results. The program runs in a loop, prompting the user to continue or exit after each sorting operation.

Uploaded by

Manoj Avhad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

/*=================================================================

===========
Name : [Link]
Title : Write a program in JAVA for Sorting
Licence : Educational
===================================================================
=========*/
package javaAssignments;

import [Link];

//import [Link];

class Sort {

void sortInterger(int a[]) {

for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

}

void sortString(String str[]) {

String temp;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (str[i].compareTo(str[j]) > 0) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}

}
}

}

}

public class EighthAssignment {

public static void main(String[] args) {

Sort obj = new Sort();
Scanner in = new Scanner([Link]);
int choice;
do {
[Link](" [Link] Integer\n [Link] String");
[Link]("Enter the choice");
int ch = [Link]();

switch (ch) {
case 1:
[Link]("Enter the size of Array ");
int n = [Link]();

[Link]("Enter the Numbers :");
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = [Link]();
[Link](arr);
// [Link](arr);
[Link]("Sorted Numbers :");

for (int i = 0; i < n; i++)
[Link](arr[i] + " ");
break;

case 2:
String names[] = { "ram", "shyam", "seeta", "geeta",
"reeta" };
[Link](names);
for (int i = 0; i < [Link]; i++)
[Link](names[i] + " ");
break;

}
[Link]("\nDo U want to continue 1 or 0?");
choice = [Link]();
} while (choice == 1);
}

}

You might also like