Vocabulary Part 1 Post
Vocabulary part 1 post for AP CSA
- Casting (Division): In coding, float/float = float, float/int = float, int/float = float, and int/int. As shown, you only need to cast one of each number in division operations.
- Casting (Truncating and Rounding): Truncation removes the decimal portion of the number, while rounding alters a number to the nearest one less precise decimal place. Casting from double to int will result in truncation.
- Wrapper Classes: Wrapper classes allow primitive data types such as int and boolean to be used as objects. The wrapper class of int is Integer. When using ArrayLists, which only store objects, we use the wrapper class Integer instead of int.
- Concatenation: The "+" operator is used to achieve concatenation, which is typically used to combine strings. When combining a string and 2 ints, the 2 ints will not be mathematically computed and will be transformed into strings from the beginning.
- Math Class: The Math class can be utilized to perform various math operations such as power and square root on number variables. The Math.random() method can be used to generate a random number. Math.random() * (max - min) + min; will generate a random number between min and max, including min but excluding max.
- Compound Boolean Expression: Created by the && symbol and multiple boolean expressions, a compound boolean expression makes it so that if the first expression is false, then the whole expression will also be false. All expressions need to be true in order for a compound boolean expression to return true.
- Truth Tables: Truth tables display all of the possible values of a logic function. Truth tables generally comprise of several rows and columns, with the top row containing all of the logical variables and combinations, and the bottom rows containing all of the possible outputs.
- De Morgan's Law: De Morgan's Law basically states that the complement of the union of 2 sets is the intersection of their complements and that the complement of the intersection of 2 sets is the union of their complements.
import java.util.ArrayList;
public class VocabOne {
public static void main(String[] args) {
System.out.println("Casting (Division):");
int x = 2;
int y = 3;
System.out.println(y/x);
System.out.println((float) y/ x);
System.out.println(y/ (float) x);
System.out.println((float) y/ (float) x);
System.out.println("");
System.out.println("Casting (Truncating and Rounding):");
double w = 3.7;
System.out.println((int) w);
System.out.println("");
System.out.println("Wrapper Classes:");
ArrayList<Integer> testArrayList = new ArrayList<Integer>();
System.out.println("ArrayList<Integer> works, but ArrayList<int> does not; " + testArrayList);
System.out.println("");
System.out.println("Concatenation:");
String one = "Hey";
int two = 2;
int three = 3;
System.out.println("one + two + three = " + one + two + three);
System.out.println("two + three + one = " + two + three + one);
System.out.println("two + one + three = " + two + one + three);
System.out.println("");
System.out.println("Math Class:");
int min = 1;
int max = 11;
int randInt = (int) Math.floor(Math.random() * (max - min) + min);
System.out.println("Randomly generated number between 1 and 10, inclusive: " + randInt);
System.out.println("");
System.out.println("Compound Boolean Expression:");
int i = 5;
int j = 10;
System.out.println(i == 5 && j == 10);
System.out.println(i == 5 && j == 5);
System.out.println("");
System.out.println("De Morgan's Law:");
System.out.println(!(i == 5 && j == 5));
System.out.println(!(i == 5) || !(j == 5));
System.out.println("");
}
}
VocabOne.main(null);