JAVA-13

Q.13 Write a Java program to display string with capital letters which are inputted through command line. Display those string(s) which starts with “B”.

Solution  :- 

public class DisplayStringsStartingWithB {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Please provide input strings as command-line arguments.");
            return;
        }
        
        System.out.println("Strings starting with 'B':");
        for (String arg : args) {
            String upperCaseArg = arg.toUpperCase();
            if (upperCaseArg.startsWith("B")) {
                System.out.println(upperCaseArg);
            }
        }
    }
}

TRY IT YOURSELF

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.