Comparing strings by their alphabetical order

前端 未结 7 2171
灰色年华
灰色年华 2020-11-27 04:26
String s1 = \"Project\";
String s2 = \"Sunject\";

I want to compare the two above string by their alphabetic order (which in this case \"Project\"

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 04:47

    import java.io.*;
    import java.util.*;
    public class CandidateCode {
        public static void main(String args[] ) throws Exception {
           Scanner sc = new Scanner(System.in);
               int n =Integer.parseInt(sc.nextLine());
               String arr[] = new String[n];
            for (int i = 0; i < arr.length; i++) {
                    arr[i] = sc.nextLine();
                    }
    
    
             for(int i = 0; i  0) {
                        String temp = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;
                    }
                }
            }
            for(int i = 0; i 

提交回复
热议问题