Week 5: Arithmetic Operator
ESCAPE CHARACTERS
public class Main {
public static void main(String[] args) {
System.out.println("This is a newline\nand this is a tab\t.");
System.out.println("This is a backslash: \\");
}
}
ASSIGNMENT OPERATORS
public class Main {
public static void main(String[] args) {
int x = 10; // Assigns the value 10 to the variable x
}
}
ARITHMETIC OPERATORS
public class Main {
public static void main(String[] args) {
int a = 10;
int b = 5;
int sum = a + b; // Addition
int difference = a - b; // Subtraction
int product = a * b; // Multiplication
int quotient = a / b; // Division
int remainder = a % b; // Modulus
}
}
RELATIONAL OPERATOR
public class Main {
public static void main(String[] args) {
int x = 10;
int y = 5;
boolean isGreaterThan = (x > y); // Greater than
}
}
BOOLEAN OPERATOR
public class Main {
public static void main(String[] args) {
boolean p = true;
boolean q = false;
boolean andResult = p && q; // Logical AND
boolean orResult = p || q; // Logical OR
boolean notResult = !p; // Logical NOT
}
}