Thursday, May 6, 2021

FLOW CONTROL AND ARRAY (Experience In JAVA)

 Flow Control 

There are four basic flow controls in java,

  • Decision-making statement -(if, if-else, if else if, nested if)
  • Iteration statement - (for, while, do-while)
  • Jumping statement -(break, continues, return, etc)
  • Branching statement -(switch)

Loop

Loop is an iteration statement which use to repeat a process with a condition satisfies.
There are 4 basic components at a loop
  • Initialization -(Starting point)
  • Condition -(Ending point)
  • Operation -(Next Phase)
  • Body -(repeat statement)

Syntax for loop

          for (Initialization; Condition; Operation)

                   {

 …......body..........

                   }

Array

An array is a derived data type that is used to make a group of data of a similar type under a unique name. Each and every element of an array have a position value known as index/indexing. The number surrounded within [] is known as sub-script, it is used to 

  • To specify dimensions
  • To access the required element

Type of Array

  • One dimension array
  • Multi dimension array
Syntax of array
Data type name[]=new Data type[size];

Example:-

Int arr[] = new int[size];

String name[] = new String[size];

In java and C/C++  array have a difference, in C/C++ array no option to declare in variable in “[]”

C/C++ :- int arr[ variable ]      “\not possible/”

For example

                             int size =10;

                             int arry[size];                   not possible

In java array have fully dynamic array have more option to declare any type;

For example:-

                   int size =20;

                   int arr[] = new arr[size]                       is possible


One Dimension Array 

Two Dimension Array


 





No comments:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...