こんにちは、私は Java の世界に不慣れで、自分のコードに行き詰まっています。
このコードのブール値に問題があります/
public class Variables {
boolean bit;
String name;
public Variables(int b, String name){
this.name = name;
bit = test(b);
}
public boolean test(int b) {
System.out.println(b);
if(b==49) {
return true;
}
if(b==48) {
return false;
}
else {
return false;
}
}
}
問題は、それがtrueを返し続けるbの数が何であれ、実際に私が試みているのは、数字の1または0の魔女を取得することであり、ブール値のt / fに変換されます
前もって感謝します
その他のコード
public class truthtable2 {
public ArrayList <Variables[]>bits = new ArrayList<>();
public truthtable2 (ArrayList <String> inputs){
String [] inputsTab = inputs.toArray(new String[inputs.size()]);
Variables[] bittab = new Variables[inputsTab.length];
int total = (int) (Math.pow(2,inputs.size()))-1;
String tab[]=new String[total+1];
for(int i =0;i<=total;i++){
tab[i]=(String.format("%16s", Integer.toBinaryString(i)).replace(' ', '0'));
}
for(int i = 0;i<tab.length;i++){
char[] chars = tab[i].toCharArray();
for(int x = 0;x<inputs.size();x++){
int d = 15-x;
bittab[x]= new Variables(chars[d], inputsTab[x]);
}
bits.add(bittab);
}
for(Variables[] d: bits){
for(int f = 0;f<d.length;f++){
System.out.format("%4s %4s \n",d[f].bit,d[f].name);
}
}
}
}
編集
'0' -->A false
'0' -->B false
'0' -->Cin false
'1' -->A true
'0' -->B false
'0' -->Cin false
'0' -->A false
'1' -->B true
'0' -->Cin false
'1' -->A true
'1' -->B true
'0' -->Cin false
'0' -->A false
'0' -->B false
'1' -->Cin true
'1' -->A true
'0' -->B false
'1' -->Cin true
'0' -->A false
'1' -->B true
'1' -->Cin true
'1' -->A true
'1' -->B true
'1' -->Cin true
編集2
この実行で
for(Variables[] d: bits){
for(int f = 0;f<d.length;f++){
System.out.format("%4s %4s \n",d[f].bit,d[f].name);
私はこの結果を持っています
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin
true A
true B
true Cin