Advertisements
Advertisements
प्रश्न
Write a program to store 6 elements in an array P and 4 elements in an array Q. Now, produce a third array R, containing all the elements of array P and Q. Display the resultant array.
Input | Input | Output |
P[] | Q[] | R[] |
4 | 19 | 4 |
6 | 23 | 6 |
1 | 7 | 1 |
2 | 8 | 2 |
3 | 3 | |
10 | 10 | |
19 | ||
23 | ||
7 | ||
8 |
थोडक्यात उत्तर
उत्तर
class Q12
{public static void main(String args[])
{
int P[] = {4., 6, 1, 2, 3, 10}, Q[] = {19, 23, 7, 8};
int size = P.length + Q.length;
int R[] = new int[size], i;
for (i = 0; i < P.length; i++)
{R[i] = P[i];}
for (int j = 0; j < Q.length; j ++)
{R[i++] = Q[j];}
for (int j = 0; j < size; j++)
{System.out.printIn(R[j]);}
}}
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 3: Arrays (Single Dimensional and Double Dimensional) - EXERCISES [पृष्ठ २४२]