Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.4 kB
3
Indexable
Never
import java.util.Scanner;

public class StringOperations {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
       
        System.out.print("Enter a string: ");
        String str = scanner.nextLine();

        int length = str.length();
        System.out.println("Length of the string: " + length);


        System.out.print("Enter the starting index for substring: ");
        int startIndex = scanner.nextInt();
        String substring = str.substring(startIndex);
        System.out.println("Substring from index " + startIndex + ": " + substring);


        String upperCaseString = str.toUpperCase();
        System.out.println("Uppercase string: " + upperCaseString);


        System.out.print("Enter a string to check if it's contained in the input: ");
        String checkString = scanner.next();
        boolean containsString = str.contains(checkString);
        System.out.println("Contains '" + checkString + "': " + containsString);

        System.out.print("Enter the delimiter to split the string: ");
        String delimiter = scanner.next();
        String[] splitStrings = str.split(delimiter);
        System.out.println("Split strings:");
        for (String s : splitStrings) {
            System.out.println(s.trim()); // Trimming extra spaces
        }

        scanner.close();
    }
}
Leave a Comment