In order to get the char version of "\u221A" (aka the square root sign), would I just do the following:

String op = "\u221A";
char operator = op.charAt(0);

operator = '\u221A';

The last part doesn't seem right. Just wondering how I'd go about doing that. Thanks for your help!

有帮助吗?

解决方案

Using the hex literal directly seems simpler than either of the approaches you state, although they all have the same effect.

public class Test {
  public static void main(String[] args) {
    String op = "\u221A";
    char operator1 = op.charAt(0);
    char operator2 = '\u221a';
    char operator3 = 0x221a;
    System.out.println(operator1 == operator2);
    System.out.println(operator2 == operator3);
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top