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.");
}
}
}
}