Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
4
Indexable
Never
import java.util.Arrays;
import java.util.Scanner;
public class StringOperations {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the first string: ");
        String str1 = scanner.nextLine();
        System.out.print("Enter the second string: ");
        String str2 = scanner.nextLine();
        String sortedStr1 = sortString(str1);
        String sortedStr2 = sortString(str2);
        System.out.println("Sorted first string: " + sortedStr1);
        System.out.println("Sorted second string: " + sortedStr2);
        boolean isSubstring = isSubstring(str1, str2);
        System.out.println("Is the first string a substring of the second string? " + isSubstring);
        String uppercaseStr1 = str1.toUpperCase();
        String uppercaseStr2 = str2.toUpperCase();
        System.out.println("Uppercase of first string: " + uppercaseStr1);
        System.out.println("Uppercase of second string: " + uppercaseStr2);
        scanner.close();
    }
    private static String sortString(String str) {
        char[] charArray = str.toCharArray();
        Arrays.sort(charArray);
        return new String(charArray);
    }
    private static boolean isSubstring(String str1, String str2) {
        return str1.contains(str2) || str2.contains(str1);
    }
}
Leave a Comment