Sorry if this is painfully obvious, but I am new to Java. I was unable to find anything answering this (at least not that I could understand). What I want to accomplish is for, when the user enters the square root symbol (√)
, the string to contain said symbol. However, when I print it, it is simply a question mark. Here is my code:
Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println(s.substring(0,1));
I am guessing that it has something to do with the scanner as when I set it up like this, it works properly.
String s = "√";
System.out.println(s.substring(0,1));
Is there some (preferably simple) way to accomplish this? My goal is not to print the character that they enter, but rather for it to be read in as √
. In case anyone is curious. I am currently working on a simple calculator with a couple functions (including the square root). Obviously, I could have the user type something like "sqrt" instead, but I would prefer to do it this way.
Thank you in advance.