presentation on array java program operators

anushaashraf20 9 views 19 slides Apr 08, 2025
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

array java program operators


Slide Content

OOPS-PPT TOPIC:ARRAYS,JAVA PROGRAM,OPERATORS SHADAN WOMEN’S COLLEGE OF ENGG. &TECH. NAME : ANUSHA ASHRAF CLASS : B.TECH 2 st YEAR 1 SEM BRANCH : AI&DS HT.NO. : 23L51A7205

INDEX ARRAYS SIMPLE JAVA PROGRAM OPERATORS TYPES OF OPERATORS

ARRAYS An array is a fundamental data structure in computer science that stores a collection of elements, all of the same type, in contiguous memory locations. Here are some key points about arrays: Fixed Size : Once an array is created, its size cannot be changed. Indexing : Elements in an array are accessed using indices, starting from 0. Efficient Access : Arrays allow for efficient access to elements using their indices. Types : Arrays can be one-dimensional or multi-dimensional (e.g., 2D arrays).

SIMPLE JAVA PROGRAM This program defines a class named  HelloWorld  with a  main  method. The  main  method is the entry point of any Java application, and  System.out.println   is used to print the text to the console. public class HelloWorld { public static void main(String[]args) { System.out.println("Hello, World!"); } } O/P: Hello World!

OPERATOR Operators in Java are the symbols used for performing specific operations in Java. Operators make tasks like addition, multiplication, etc. which look easy although the implementation of these tasks is quite complex. Operators are the building blocks of Java expressions, allowing you to perform calculations, comparisons, and more.

TYPES OF OPERATORS A rithmetic Operators Relational Operators Logical Operators Assignment Operator Increment Or Decrement Operators Conditional operator Bitwise operator Shift Operator Instance Operator

Arithmetic Operators Program: Java Program to implement Arithmetic Operators class ArithmeticOperators { public static void main(String[] args ) Int a=12,b=5; System.out.printIn ("a + b ="+ ( a+b )); System.out.printIn (“a- b=" + (a-b)); System.out.printIn ("a * b =" + (a * b)); System.out.printIn ("a / b =" + (a /b)); System.out.printin ("a % b=" + ( a%b )); } Arithmetic Operators are used for mathematical calculations.

Relational Operators Program: Java Program to implement Relational Operators class RelationalOperator public static void main(String[] args ) { Int a = 10; intb =3; intc =5; System.out.printin ("a > b:" + (a> b)); System.out.printin ("a < b:" + (a<b)); System.out.printin ("a >= b:" + (a >= b)); System.out.println ("a <= b:" + (a <= b)); System.out.println ("a == c:" + (a == c)); System.out.println ("a != c: "+ (a !=c)); } Relational operators are used to compare two values and return a true or false result based upon that comparison. Relational operators are of 6 types.

Logical Operators The Logical operators are used to combine two or more conditions .Logical operators are of three types. 1. Logical AND (&&), 2. Logical OR (||) 3. Logician NOT (!) Example of Logical Operators class LogicalOp { public static void main(String[] args ) { int x=10; System.out.printIn (x==10 && x>=5)); System.out.printIn (x==10 || x>=5)); System.out.printin (! (x==10 )); }

Logical AND(&&): Logical AND (&&) : Logical AND is denoted by double ampersand characters (&&).it is used to check the combinations of more than one conditions. if any one condition false the complete condition becomes false.

Logical OR (||) Logica l OR (||): The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise.

Logical NOT(!): Logician NOT (!): Logical NOT is denoted by exclamatory characters (!), it is used to check the opposite result of any given test condition. i.e , it makes a true condition false and false condition true.

ASSIGNMENT OPERATOR Assignment operators are used to assign a value (or) an expression (or) a value of a variable to another variable. Syntax : variable name=expression (or) value class AssignmentOperator { public static void main(String[] args ) { int a=4; int var; var =a; System.out.printIn(“var using =: " + var); var += a; System.out.printIn("var using +=:" + var); var *= a; System.out.printin("var using *=:" + var);

INCREMENT & DECREMENT OPERATIORS The increment and decrement operators are very useful. ++ and == are called increment and decrement operators used to add or subtract. Both are unary operators. class Increment { public static void main(String[] args ) { int var=5; System.out.printIn (var++); System.out.printin (++var); System.out.printin (var--); System.out.printIn (--var); }

CONDITIONAL OPERATOR A conditional operator checks the condition and executes the statement depending on the condition. Conditional operator consists of two symbols. 1: question mark (?). 2:colon(:). class ConditionalOperator { public static void main(String[] args ) { int februaryDays = 29; String result; result = ( februaryDays == 28) ? "Nota leap year" : "Leap year"; System.out.println (result); }

BITWISE OPERATORS Bitwise operators are used for manipulating a data at the bit level, also called as bit level programming. Bit-level programming mainly consists of 0 and 1. public class  BitwiseAndExample { public static void main(String[] args ) { int x = 9, y = 8; // bitwise AND System.out.println ("x & y = " + (x & y)); } }

SHIFT OPERATOR A shift operator performs bit manipulation on data by shifting the bits of its first operand right or left. Left Shift (<<): Multiplies the operand by 2 for each shift. Example: int x = 5; int y = x << 2; // y becomes 20 Right Shift (>>): Divides the operand by 2 for each shift. Preserves the sign. Example: int x = -10; int y = x >> 2; // y becomes -3 Unsigned Right Shift (>>>): Fills leftmost bits with 0s. Example: int x = -10; int y = x >>> 2; // y becomes 1073741821

Instance Operator Checks if an object is an instance of a class. Syntax: expression instanceof type Returns: true or false EXAMPLE: Object obj = new String("Hello"); if (obj instanceof String) { System.out.println ("obj is a String object"); }

Thank you
Tags