0% found this document useful (0 votes)
5 views8 pages

Java Operator Program

The document provides beginner-level Java programs demonstrating various operators, including arithmetic, unary, relational, logical, and ternary operators. Each program includes a brief description of the operator used, the code implementation, and the expected output. Examples include addition, subtraction, multiplication, division, modulus, increment, decrement, relational checks, logical operations, and the ternary operator.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Java Operator Program

The document provides beginner-level Java programs demonstrating various operators, including arithmetic, unary, relational, logical, and ternary operators. Each program includes a brief description of the operator used, the code implementation, and the expected output. Examples include addition, subtraction, multiplication, division, modulus, increment, decrement, relational checks, logical operations, and the ternary operator.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practice Programs – Operators in Java

Beginner Level Programs (Arithmetic, Unary, Relational, Logical, Ternary)

Program 1: Addition of Two Numbers


Concept: Arithmetic operator (+)

Program:

class Addition

public static void main()

int a = 10;

int b = 5;

int sum = a + b;

[Link]("Sum = " + sum);

Output:

Sum = 15

Program 2: Subtraction Example


Concept: Arithmetic operator (-)
Program:

class Subtraction

public static void main()

int a = 20;

int b = 8;

int result = a - b;

[Link]("Result = " + result);

Output:

Result = 12

Program 3: Multiplication Example


Concept: Arithmetic operator (*)

Program:

class Multiplication

public static void main()

{
int a = 6;

int b = 4;

int product = a * b;

[Link]("Product = " + product);

Output:

Product = 24

Program 4: Division Example


Concept: Arithmetic operator (/)

Program:

class Division

public static void main()

int a = 20;

int b = 4;

int result = a / b;

[Link]("Division = " + result);


}

Output:

Division = 5

Program 5: Modulus Example


Concept: Arithmetic operator (%)

Program:

class ModulusExample

public static void main()

int a = 17;

int b = 5;

int remainder = a % b;

[Link]("Remainder = " + remainder);

Output:

Remainder = 2
Program 6: Increment Operator
Concept: Unary operator (++ )

Program:

class IncrementDemo

public static void main()

int a = 10;

a++;

[Link]("Value of a = " + a);

Output:

Value of a = 11

Program 7: Decrement Operator


Concept: Unary operator (--)

Program:

class DecrementDemo

public static void main()


{

int a = 10;

a--;

[Link]("Value of a = " + a);

Output:

Value of a = 9

Program 8: Relational Operator Example


Concept: Relational operator (>)

Program:

class RelationalExample

public static void main()

int a = 10;

int b = 5;

boolean result = a > b;

[Link](result);
}

Output:

true

Program 9: Logical Operator Example


Concept: Logical operator (&&)

Program:

class LogicalExample

public static void main()

int a = 10;

int b = 5;

boolean result = (a > 5) && (b < 10);

[Link](result);

Output:

true
Program 10: Ternary Operator Example
Concept: Ternary operator

Program:

class TernaryExample

public static void main()

int a = 10;

int b = 20;

int max = (a > b) ? a : b;

[Link]("Maximum number = " + max);

Output:

Maximum number = 20

You might also like