0% found this document useful (0 votes)
10 views2 pages

Array Prog

Uploaded by

Iswarya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
10 views2 pages

Array Prog

Uploaded by

Iswarya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

PRINTING OF SINGLE ARRAY:

import java.util.*;
import java.util.Scanner;
public class Main{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int[] arr = {1,2,3,4,5};
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]);
}
}
}

SUM OF THE 2 ARRAY:

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter the size of the arrays : ");
int size=in.nextInt();
int[] arr1 = new int[size];
int[] arr2 = new int[size];
System.out.println("Enter the Element for the 1st array : ");
for(int i=0;i<size;i++){
System.out.print("Element of arr1: " +(i+1)+ " : ");
arr1[i] = in.nextInt();
}
for(int i=0;i<size;i++){
System.out.print("Element of arr2: " +(i+1)+ " : ");
arr2[i] = in.nextInt();
}
int[] sum = new int[size];
for(int i=0;i<size;i++){
sum[i]=arr1[i]+arr2[i];
}
System.out.println("Sum of the two Array");
for(int i=0;i<size;i++){
System.out.println("Element " +(i+1)+ " : " +sum[i]);
}
}
}

PRINT THE 2 ARRAY ELEMENTS:

import java.util.Scanner;
public class Main{
public static void main(String[] args){
int[] arr1 = {10,5,6};
int[] arr2 = {3,6,9};
System.out.println("Array1 : ");
printArray(arr1);
System.out.println("Array2 : ");
printArray(arr2);
}
public static void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}

You might also like