Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author HieuDuong
- */
- import java.util.Scanner;
- public class Ex2Tut5 {
- public static void bubbleSort(String[] stringArray) {
- int n = stringArray.length;
- String temp;
- for (int i = 0; i < n; i++) {
- for (int j = 1; j < (n - i); j++) {
- if (stringArray[j - 1].compareTo( stringArray[j] ) > 0) {
- temp = stringArray[j - 1];
- stringArray[j - 1] = stringArray[j];
- stringArray[j] = temp;
- }
- }
- }
- }
- public static void main( String[] args ) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the size of array: ");
- int size = sc.nextInt();
- String[] Arrays = new String[size];
- for(int i = 0; i < size; i++) {
- if (Arrays[i].length() != size) {
- System.out.println("String index not equal!");
- }
- Arrays[i]= sc.nextLine();
- }
- bubbleSort(Arrays);
- for(int i = 0; i < size; i++) {
- System.out.println("The sorted array is: " + Arrays[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement