Truth Tables Kotlin (Android Studio)


#1

Hello everyone

My next code printed the tables of false and true, but I would like to implement let’s say that a true boolean and a boolean false, I work like the logical tables of truth, but he tried and it does not work the sum of these that you could implement?

indent preformatted text by 4 spaces

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val textview:TextView = findViewById(R.id.textview) as TextView

val a = true;
val b = false;

val a1 = a && a
val a2 = a && b
val a3 = b && a
val a4 = b && b

val b1 = a || a
val b2 = a || b
val b3 = b || a
val b4 = b || b

val c1 = a xor a
val c2 = a xor b
val c3 = b xor a
val c4 = b xor b

val d1 = !a and b
val d2 = a and !b

val myString0 = “Tabla de AND \n”;

var myString011 = $p1 + $a = $a1 \n;
val myString2 = “$a y $a = $a1 \n”;
val myString3 = “$a y $b = $a2 \n”;
val myString4 = “$b y $a = $a3 \n”;
val myString5= “$b y $b = $a4 \n”;

val myString6 = “\n”;
val myString7 = “Tabla de OR \n”;

val myString8 = “$a y $a = $b1 \n”;
val myString9 = “$a y $b = $b2 \n”;
val myString10 = “$b y $a = $b3 \n”;
val myString11 = “$b y $b = $b4 \n”;

val myString12 = “\n”;
val myString13 = “Tabla de XOR \n”;

val myString14 = “$a y $a = $c1 \n”;
val myString15 = “$a y $b = $c2 \n”;
val myString16 = “$b y $a = $c3 \n”;
val myString17 = “$b y $b = $c4 \n”;

val myString18 = “\n”;
val myString19 = “Tabla de NOT \n”;

val myString20 = “$a y $b = $d1 \n”;
val myString21 = “$a y $b = $d2 \n”;

textview.setText( myString0 + myString2 + myString3 + myString4 + myString5 + myString6 + myString7 + myString8 + myString9 + myString10 + myString11 +myString12 +myString13 + myString14 + myString15
+ myString16 + myString17 + myString18 + myString19 + myString20 + myString21)

textview.setMovementMethod(ScrollingMovementMethod())
}

}


#2

I am very new, I do this exercise to be able to learn