At compile time this line:
System.out.println(new String("\44"));
will print ACSII char "$"
But, how to print it when "\44" is passed as command-line argument?
You basically strip the leading \ and use Integer.parseInt(arg, 8) since octal is base 8.
public static void main(String[] args) throws Exception {
String arg = "\\44"; // simulate command line
String argOctal = arg.substring(1); // get rid of leading \ to get an octal integer
int codePoint = Integer.parseInt(argOctal, 8);
System.out.println('\44');
System.out.println((char)codePoint);
}
prints
$
$
This assumes you ran like
java YourClass "\44"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With