ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2010 ICSE Computer Science Paper



Share with a Friend

Solved 2010 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Combine Two Arrays in Third Array Program - ICSE 2010 Computer Science

Write a program to store six elements in an array P, and four elements in an array Q and produce a third array R, containing all elements of arrays P and Q. Display the resultant array.
Example:
P[] = {4, 6, 1, 2, 3, 10}
Q[] = {19, 23, 7, 8}
R[] = {4, 6, 1, 2, 3, 10, 19, 23, 7, 8}

import java.util.Scanner; class MyArray{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int p[] = new int[6]; int q[] = new int[4]; int r[] = new int[10]; System.out.println("Enter 6 elements:"); for(int i = 0; i < 6; i++) p[i] = Integer.parseInt(in.nextLine()); System.out.println("Enter 4 elements:"); for(int i = 0; i < 4; i++) q[i] = Integer.parseInt(in.nextLine()); int i = 0; int k = 0; for(i = 0; i < 6; i++) r[k++] = p[i]; for(i = 0; i < 4; i++) r[k++] = q[i]; System.out.println("Elements in the third array:"); for(i = 0; i < 10; i++) System.out.println(r[i]); } }

Output

 
 OUTPUT : 
Enter 6 elements:
4
6
1
2
3
10
Enter 4 elements:
19
23
7
8
Elements in the third array:
4
6
1
2
3
10
19
23
7
8