Thursday, February 29, 2024

Java program to find length of given string and convert it in to upper or lower case.

import java.util.Scanner;

public class StringCaseConverter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a string: ");
        String inputString = scanner.nextLine();

        int length = inputString.length();

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

        System.out.println("Choose an operation:");
        System.out.println("1. Convert to Uppercase");
        System.out.println("2. Convert to Lowercase");

        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                System.out.println("Uppercase: " + inputString.toUpperCase());
                break;
            case 2:
                System.out.println("Lowercase: " + inputString.toLowerCase());
                break;
            default:
                System.out.println("Invalid choice");
        }
    }
}

No comments:

Post a Comment

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...