I'm trying to do CNF operator in Java and I have an error with equality.
Firstly, I did most of the software but I didn't do totally.
My codes are here :
import acm.program.*;
public class split extends ConsoleProgram{
public void run()
{
String veri = "(p or q or s or t or k) and (p or q)";
String yeni = tekrarsil(parcala(veri));
int []sayilar = new int[yeni.length()];
for (int i = 0; i < yeni.length(); i++) {
sayilar[i] = readInt("give a number for "+yeni.charAt(i)+" :");
}
for (int i = 0; i < sayilar.length; i++) {
println(sayilar[i]);
}
}
public String parcala(String veri)
{
String yenistr = "";
String yeni[] = veri.split("and");
for (int j = 0; j < yeni.length; j++) {
String yveri[] = yeni[j].split("or");
for (int i = 0; i < yveri.length; i++) {
yveri[i] = yveri[i].trim();
if(i==0){
yenistr = yenistr.concat(yveri[i].substring(1));
}else if(i==yveri.length-1){
yenistr = yenistr.concat(yveri[i].substring(0,yveri[i].length()-1));
}else{
yenistr = yenistr.concat(yveri[i]);
}
}
}
return (yenistr);
}
public String tekrarsil(String S)
{
for (int i = 0; i < S.length(); i++)
for (int k = i+1; k <= S.length()-1; k++){
if (S.charAt(i) == S.charAt(k))
{
S = S.substring(0,k)+ S.substring(k+1,S.length());
k--;
}
}
return S;
}
}
The problem is the equality.
The program should check the variables is true
or false
.
For instance :
(p or q or s or t or k) and (q or p)
this program does like bellow:
give a number for p : 1(user will give a number one (true
) or zero(false
))
give a number for q : 0
give a number for s : 1
give a number for t : 0
give a number for k : 0
(if the variable use more than one, program will ask once)
If we look at these variables, we can see that (1 or 0 or 1 or 0 or 0) and (1 or 0) It will return true but I can't do this. I can't understand how to do it.
Best wishes.