Start reading this
Kotlin Intro document to learn about Kotlin.
For each question, give the answer in Java and Kotlin.
int double char booleanAns: 4; 8; 2; 1. The reason that a char variable take up two bytes it that is uses Unicode characters, which in Java take up two bytes. A boolean variable should only take up one bit, but a byte is the smallest addressable unit on a computer, so a boolean variable must take up one byte.
var n : Int = 385;
var x : Double = 3.14159;
var c : Char = 'A';
var s : String = "abc";
println("$n $x $c $s")
Variables can also be declared using duck typing (if it looks like a duck and
quacks like a duck, it's a duck). This means that the variable type is inferred
by the value assigned to it.
var n = 385;
var x = 3.14159;
var c = 'A';
var s = "abc";
println("$n $x $c $s")
// Java version:
for (int n = 99; n >= 1; n -= 2) {
System.out.println(n);
}
// Kotlin version:
for (n = 00 downto 1 step 2) {
println(n)
}
String word;
if (n == 1) {
word = "one";
}
else if (n == 2) {
word = "two";
}
else {
word = "many";
}
Answer:
// Java version:
String word = "";
switch(n) {
case 1: word = "one"; break;
case 2: word = "two"; break;
default: word = "many";
}
// Kotlin verson:
var word = when(n) {
1 -> "one"
2 -> "two"
else -> "many"
}
android:text android:background android:textColor android:textSize
app src main java resAns: Here are the paths to each of these folders:
app: TextDisplay/app src: TextDisplay/app/src java: TextDisplay/app/src/main/java res: TextDisplay/app/src/main/res
MainActivity.java activity_main.xmlAns: Look in the Project Explorer on the left of Android Studio. The Java file is found at
app >> it372.ssmith.textdisplay >> MainActivity.javaThe XML layout file is found at
app >> res >> layout >> activity_main.xmlHere are the actual paths to each of these folders on the harddrive:
TextDisplay/app/src/main/java/it372/ssmith/textdisplay/MainActivity.java TextDisplay/app/src/main/res/layout/activity_main.xml