Here you can find the source of negateExpression(String expression)
private static String negateExpression(String expression)
//package com.java2s; //License from project: Open Source License public class Main { private static final char TERM_DELIMITER = '+'; private static final char FACTOR_DELIMITER = '*'; private static final char NEGATION_DELIMITER = '!'; private static String negateExpression(String expression) { String result = null;//from w w w .ja va 2s. c o m if (expression.contains("" + TERM_DELIMITER) || expression.contains("" + FACTOR_DELIMITER)) { result = NEGATION_DELIMITER + "(" + expression + ")"; } else { if (expression.startsWith("!")) { result = expression.substring(1, expression.length()); } else if (expression.endsWith("'")) { result = expression.substring(0, expression.length() - 1); } else { result = "!" + expression; } } return result; } }