JAVA-10

Q.10 Write a java program that accepts string from command line and display each character in capital at the delay of one second.

Solution :- 

public class DisplayCharsWithDelay {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Error: Please provide a string as a command-line argument.");
            return;
        }
        
        String input = args[0].toUpperCase();
        
        for (char ch : input.toCharArray()) {
            System.out.println(ch);
            try {
                Thread.sleep(1000); // Delay of 1 second
            } catch (InterruptedException e) {
                System.out.println("Error: Thread interrupted.");
            }
        }
    }
}

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.