Logo Questions Linux Laravel Mysql Ubuntu Git Menu

How to read propositional logic symbols as input using Java Scanner?

 Scanner in = new Scanner(System.in,"UTF-8");

If I paste , I receive ? as output to the console. Can someone explain what I can do to properly read logic symbols like this? I'm using NetBeans 8.0.1.


like image 200
mmgro27 Avatar asked Mar 15 '23 17:03


1 Answers

The problem is not with entering the character, but rather with printing it to console. Your console does not appear to support the code point \u2227 of , so it prints a question mark instead.

You should test if console lets you input correctly by printing the numeric representation of the character that you read, like this:

Scanner in = new Scanner(System.in,"UTF-8");
String s = in.next();
if (s.length() != 0) {

If 8743 gets printed, you could process the character internally: comparisons like this

if (s.equals("∧")) {

will work correctly.

Otherwise, you should switch to using characters from the first code page, i.e. ^ instead of

like image 179
Sergey Kalinichenko Avatar answered Mar 18 '23 06:03

Sergey Kalinichenko