Page 141 - ComputerScience_Class_11
P. 141

Array
                 Arrays can be defined as a collection of elements of the same data type stored under a single variable name. Each
                 element in the array is identified by its index (subscript) which helps to access or separate the values. When we declare
                 an array we create a structure that can store multiple values of the same type together.
                 The syntax to declare an array is as follows:

                   Primitive_Datatype variable_name[]= new  Primitive_Datatype[size];
                 For example,

                   int ar[]= new int[10];         //it creates an integer array of 10 elements
                 Interface
                 An interface is an abstract class contains a combination of methods and variables. But the methods declared in an
                 interface have signatures only. By default, all methods in an interface are abstract and the variables are public, static
                 and final. For example,
                   interface fan
                   {
                      void show();
                   }
                 String
                 A string is a  sequence of characters stored in a single variable. They are written within “ ” (double quotation marks).
                 Unlike C/C++, Java strings are not terminated with a null character. Syntax of declaring a string:
                   String <variable> = "sequence_of_characters";

                     6.4 ARITHMETIC EXPRESSION
                 The arithmetic expressions are the expressions that contain variables, constants and arithmetic operators. They are
                 used to perform mathematical calculations. For example,
                   int a = 5, b = 6;
                   double c;
                   c = (a+b)/2.0;

                 6.4.1 Types of Arithmetic Expressions
                 There are two types of arithmetic expressions.
                 •  Pure arithmetic expression: When the variables and constants in an expression are of the same data type, then the
                   expression is known as a pure arithmetic expression. For example,

                   int a,b,c;
                   a = 100;
                   b = 200;
                   c = a+b;
                   In the above expression, all the variables are of integer type.
                 •  Mixed arithmetic expression: When the variables and constants in an expression are of different data types, then
                   the expression is known as a mixed arithmetic expression. For example,
                   int a;
                   float b;
                   double c;
                   a = 100;
                   b = 200.20f;
                   c = a + b;
                   In the above expression, the variables are of different data types.




                                                                      Primitive Values, Wrapper Classes, Types and Casting  139
   136   137   138   139   140   141   142   143   144   145   146