JAVA

Q.1 Write a java program to enter strings at command line input and then sort strings into ascending order.

import java.util.Arrays;

public class SortStrings {
    public static void main(String[] args) {
        // Check if there are any command-line arguments
        if (args.length == 0) {
            System.out.println("Please enter strings as command-line arguments.");
            return;
        }
        
        // Sort the array of strings
        Arrays.sort(args);
        
        // Print the sorted strings
        System.out.println("Sorted Strings in Ascending Order:");
        for (String str : args) {
            System.out.println(str);
        }
    }
}

Solution

TRY THIS CODE 

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.