Vocab Part 1
Casting - Unit 1 (Primitives)
Below, there are two examples of casting. Both examples convert a double data type to integer via truncation. 1.511 is outputted as 1 in the first line. 28.2 is printed as 28 in the second line. This can simplify the output and make it easier to operate on in future code as well.
double d1 = 6.53;
double d2 = 4.32;
// Casting for division
int dd = (int) (d1/d2);
// Casting for multiplication
int md = (int) (d1*d2);
System.out.println(dd); // output of division, is integer
System.out.println(md); // output of multiplication, is integer
int i = 1;
Integer ii = 1;
// String unwrapped = i.toString();
String wrapped = ii.toString();
System.out.println(i);
System.out.println(ii);
String s1 = "hello";
String s2 = "world";
String conc = s1.concat(s2);
System.out.println(s1+ " " + s2);
System.out.println(conc);
System.out.println(s1 + " " + s2 + " " + 12);
int ex = -1;
System.out.println(Math.abs(-1));
// random between 1 and 10
System.out.println((int)(Math.random() * (100-10) + 10));
System.out.println((Math.random() * (10-1) + 1));
boolean a = true;
boolean b = false;
System.out.println(!a && !b);
boolean a = true;
boolean b = false;
System.out.println(!(a&&b));
System.out.println(!a || !b);
System.out.println(!(a||b));
System.out.println(!a && !b);