Dain1234 / Java-Programming

0 stars 0 forks source link

Alphabetical order #2

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

package com.dain.logics;

public class Alphaorder { public static void main(String[] args) { String a[] = { "Banana", "Apple", "Mango", "Kaka", "Rambo" }; int len = a.length; for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (a[i].compareTo(a[j]) > 0) { String temp = a[i]; a[i] = a[j]; a[j] = temp; } }

    }
    for (int i = 0; i < len; i++) {
        System.out.println(a[i]);
    }
}

}