Primitive Data Types [Java Code Snippets]

public class Intro {

// Hello this is a comment

// "Hello this a comment"

/**
Project Name: My very first code!
Name: Bob
Date: 1/31/21
**/

// Print Statement
System.out.println("Hello world!");

// variables
int x = 4;
double double2 = 2.4;
char repel = 'A';
boolean truefalse = true; // can only be set to true or false

// constants
final double doubler = 2.0;

// arithmetic expressions - assignment operators
double y = x + double2;
double z = x - double2;
double a = x * double2;
double b = x / double2;

int c = 10/3; // make c 3 because it chops off whatever is after the decimal point - integer division

System.out.println(y+ " " + z + " " + a + " " + b); // "" represent a string

// boolean conditions
truefalse = false; // true and false are the only conditions for boolean

if (true) { // our selection statements are controlled by boolean true/false
System.out.println("Hello world!");
}

if (false) {
System.out.println("Hello world!");
}

// comparison operators < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal) == (true equality)

if (z < y) {
System.out.println("yay!");
}

if (z > a) {
System.out.println("ok!");
}

// boolean operators: && (and) both needs to be true to be true and || (or) one is true for true

if ((z<y)&&(z>a)) {
System.out.println("whoop!");
}

if ((z<y)||(z>a)) {
System.out.println("Alright!");
}

}