Modify the program to use command-line arguments
You can modify the Java code to accept the input character or string from the command line arguments instead of prompting the user to enter the input. Here's how you can modify the code:
public class IsSurrogateDemo {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Please enter a character or string as command-line argument.");
return;
}
for (String arg : args) {
for (int i = 0; i < arg.length(); i++) {
char ch = arg.charAt(i);
boolean isSurrogateChar = Character.isSurrogate(ch);
if (isSurrogateChar) {
System.out.println(ch + " is a surrogate code unit.");
} else {
System.out.println(ch + " is not a surrogate code unit.");
}
}
}
}
}
Compile and run the modified program using the following commands (replace "e" with any character or string of your choice):
javac IsSurrogateDemo.java
java IsSurrogateDemo e