0% found this document useful (0 votes)
9 views2 pages

Week 5 Arithmetic Operator

The document provides examples of various operators in Java programming, including escape characters, assignment operators, arithmetic operators, relational operators, and boolean operators. Each section includes code snippets demonstrating the usage of these operators. The document serves as a basic guide for understanding operator functionality in Java.

Uploaded by

Penny Clarkton
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Week 5 Arithmetic Operator

The document provides examples of various operators in Java programming, including escape characters, assignment operators, arithmetic operators, relational operators, and boolean operators. Each section includes code snippets demonstrating the usage of these operators. The document serves as a basic guide for understanding operator functionality in Java.

Uploaded by

Penny Clarkton
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

}
}

You might also like