Advertisements
Advertisements
प्रश्न
Write a program for the following.
Fill two arrays TA[ ] and TB[ ] of size 7 and type integer each. Create a third array TC[ ] that contains the elements of the second array (TB[ ]) followed by the elements of the first array (TA [ ]).
| Input | TA[ ] | 21 | 31 | 41 | 51 | 61 | 23 | 43 |
| TB[ ] | 28 | 38 | 48 | 58 | 68 | 78 | 16 | |
| Output | TC[ ] | 28 | 38 | 48 | 58 | 68 | 78 | 16 |
| 21 | 31 | 41 | 51 | 61 | 23 | 43 | ||
कोड लेखन
Advertisements
उत्तर
import java.util.Scanner;
public class MergeArrays
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int TA[] = new int[7];
int TB[] = new int[7];
int TC[] = new int[14];
System.out.println("Enter 7 integers for array TA:");
for (int j = 0; j < TA.length; j++)
{
TA[j] = sc.nextInt();
}
System.out.println("Enter 7 integers for array TB:");
for (int j = 0; j < TB.length; j++)
{
TB[j] = sc.nextInt();
}
for (int j = 0; j < TB.length; j++)
{
TC[j] = TB[j];
}
for (int j = 0; j < TA.length; j++)
{
TC[TB.length + j] = TA[j];
}
System.out.println("\nOutput TC[ ]:");
for (int j = 0; j < TC.length; j++)
{
System.out.print(TC[j] + " ");
if (j == 6)
{
System.out.println("\n");
}
}
sc.close();
}
}shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Arrays - One Dimension - Exercises [पृष्ठ १७६]
