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