Welcome To Search How
Hello dosto aaj firse aapka welcome hai humare blog Tips Arena main, dosto humne apni peechli post main seekha tha java strings ke bare main or dosto ab hum study karenge java arrays ke bare main.
Java Arrays Introduction
Friends ek array similar data type ki value ka collection hota hai, dosto array se hum similar information ka group bna sakte hain for example hum kisi employee ki salary ka array bana kar us sabhi employees ki salary store karwa sakte hain.Friends isme hume kisi bhi type ka array create karna hain to vo hum kar sakte hain for example ==> int, float, char etc.. dosto jab bhi hum jis trah ka variable create karte hain usme usi trah ki value daal sakte hain, dosto jab kabhi bhi hum array create karte hain to hume uski size bhi define karwani hoti hai.
Friends hum aapko ek baat or batana chahte hain vo ye hai ki jitni bhi array ki size hoti hai hume utni hi values store karwani hoti hai or usme utni hi value store ki ja sakti hai. dosto array sari values ko indexing ke through store karta hai or har index ek different variable ko represent karti hai.
array_name[0]; // first variable
array_name[1]; // second variable
..
..
array-name[n-1]; // last variable
Friends hum aapko bata de Arrays ki index zero se start hoti hai or isliye for example ==> humare array ka size n hai to last element (n-1) position par store hota hai.
Element
|
4
|
6
|
9
|
10
|
22
|
Index
|
0
|
1
|
2
|
3
|
4
|
Friends jesa ki uper table main diya hua hai ki array ki size 5 hai but array ka last element 22 4th position pe store ho raha hai vo isliye kyunki array ki index zero se start ho rahi hai.
Creating Java Arrays In Hindi
Friends ab hum aapko creating java arrays ke bare main information denge dosto java main arrays create karna koi muskil kaam nahi hai ye kafi jada easy hota hai for example ==>type arrayName = new type[arraySize];
dosto ab hum aapko inke bare main puri jankari denge :-
type
|
Friends hume jis type ka array create karna hota hai ye uske liye
hota hai.
|
arrayName
|
Friends isme hum apne array ka name likhte hain dosto humesa dhyan
rakhe ki jitna ho sake hume apna name unique hi rakhna chahiye.
|
new
|
Friends jab hume array ko memory allocate karna hota hai tab hum iska
use karte hain jiska name new keyword hai.
|
arraySize
|
Friends ye humare array ki size hoti hai, ye isi se hume pta chalta
hai ki hume array main kitne elements store karne hain, or ise hum kisi
integer se hi define karte hain.
|
int salary = new int[10];
Initializing Arrays In Hindi
Friends ab hum baat karte hai Initializing arrays ke bare main or hum janenge ki arrays ko kaise intialize kiya jata hai, dosto hum bata de arrays ko hum 2 trah se intialize kar sakte hain :-- Variable Ki Trah
- Loop use karke
Variable Ki Trah
Dosto hum java ki hi trah se kisi index ko intialize kar sakte hain for example ==>
salary[0] = 35000;
salary[1] = 20000;
..
..
salary[9] = 40000
dosto hum aapko bta de ki user ke through bhi isme value input ki ja sakti hai.
Scanner s = new Scanner(System.in);
salary[0] = s.nextInt();
Friends is trah se hum apna kafi time bacha sakte hain or ye tarika time consuming ke liye bahut hi kargar hai.
Loop use karke
Friends second tarika ye h ki hum ek loop use karte hain or sabhi values ko ek saath input karwa lete hain.
Scanner s = new Scanner(System.in);
for(int i=0;i<10;i++)
{
salary[i] = s.nextInt();
}
Displaying Arrays In Hindi
Friends hum baat karenge arrays kese display karwate hain, dosto arrays ki value ko hum 2 tariko se print karwa sakte hain or pure array ko bhi print karwa sakte hain.System.out.println(salary[10]); // prints value of first index
for (int i=0; i<10;i++)
{
System.out.println(salary[i]); // prints all array
}
Multidimensional Java Arrays In Hindi
Friends aayiye ab hum baat karte hain multidimensional java arrays ke bare main, dosto hum aapko batana chahte hain ki abhi tak uper jo bhi humne examples dekhe vo sabhi one dimensional array hai, dosto arrays ke kafi sare dimension ho sakte hain, dosto ab hum aapko two dimensional arrays ki bare main batayenge.Friends two dimensional array create karne ke liye hum row or column size dete hain, dosto ye koi table create karne jesa hota hai, dosto isme pehle square brackets rows ko or dusre brackets column ko represent karte hain.
Creating two dimensional arrays
int TwoDiem [] [] = new int [3][4];
Initializing two dimensional arrays
Scanner s = new Scanner(system.in);
System.out.println("Enter the array elements");
for(int i=0; i<3;i++)
{
for(int j=0; j<4;j++)
{
TwoDiem[] [] = s.nextInt();
}
}
Displaying Two Dimensional Arrays
for(int i = 0; i<3; i++)
{
for(int j=0; j<4; j++)
{
System.out.println(TwoDiem[i][i]);
}
}
No comments:
Post a Comment