ADD TWO MATRICES OF THE SAME SIZE
import java.util.Arrays;
import java.util.Scanner;
public class AddTwoMatricesOfSameSize {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int arr1[][]=new int[a][b];
int arr2[][]=new int[a][b];
int sum[][]=new int[a][b];
System.out.println("the first matrix is:");
for(int i=0;i<a;i++) {
for(int j=0;j<b;j++) {
arr1[i][j]=sc.nextInt();
}
}
System.out.println("the second matrix is:");
for(int i=0;i<a;i++) {
for(int j=0;j<b;j++) {
arr2[i][j]=sc.nextInt();
}
}
//System.out.println("the arr2 is:"+Arrays.toString(arr2));
for(int i=0;i<a;i++) {
for(int j=0;j<b;j++) {
sum[i][j]=arr1[i][j]+arr2[i][j];
}
}
System.out.println("the sum of matrix is:");
for(int i=0;i<a;i++) {
for(int j=0;j<b;j++) {
System.out.print(sum[i][j]+"\t");
}
System.out.println();
}
}
}
AVERAGE VALUE OF AN ARRAY
import java.util.Scanner;
public class AverageValueOfAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<arr.length;i++) {
sum+=arr[i];
}
double ave=sum/arr.length;
System.out.println("the average value is:"+ave);
}
}
CheckArrayOfIntegeresWithoutSpecificNumbers
import java.util.Arrays;
import java.util.Scanner;
public class CheckArrayOfIntegeresWithoutSpecificNumbers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the original array is:"+Arrays.toString(arr));
System.out.println("without specific number array is:"+remove(arr));
}
public static boolean remove(int arr[]) {
for(int numbers:arr) {
if(numbers==0 || numbers==-1) {
return false;
}
}
return true;
}
}
CheckIfAnArrayOfIntegersContainsTwoSpecifiedElements
import java.util.Arrays;
import java.util.Scanner;
public class CheckIfAnArrayOfIntegersContainsTwoSpecifiedElements {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int num1=sc.nextInt();
int num2=sc.nextInt();
System.out.println("the result is:"+result(arr,num1,num2));
}
public static boolean result(int arr[],int num1,int num2) {
for(int number:arr) {
boolean r=number!=num1 && number!=num2;
if(r) {
return false;
}
}
return true;
}
}
CheckIfTheSumOfAllThe10sInTheArrayIsExactly30
import java.util.Arrays;
import java.util.Scanner;
public class CheckIfTheSumOfAllThe10sInTheArrayIsExactly30 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int search=sc.nextInt();
int fix=sc.nextInt();
System.out.println("the result is:"+result(arr,search,fix));
}
public static boolean result(int arr[],int search,int fix) {
int temp=0;
for(int numbers:arr) {
if(numbers==search)
temp+=search;
if(temp>fix) {
break;
}
}
return temp==fix;
}
}
ChecksSpecificValue
import java.util.Scanner;
public class ChecksSpecificValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println(contains(arr,2013));
System.out.println(contains(arr,2015));
}
public static boolean contains(int arr[],int item) {
for(int n:arr) {
if(item==n) {
return true;
}
}
return false;
}
}
CommonIntVlauesBetweenArray
import java.util.Arrays;
import java.util.Scanner;
public class CommonIntVlauesBetweenArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int arr1[]=new int[a];
int arr2[]=new int[b];
for(int i=0;i<a;i++) {
arr1[i]=sc.nextInt();
}
System.out.println("the original arr1 is:"+Arrays.toString(arr1));
for(int i=0;i<b;i++) {
arr2[i]=sc.nextInt();
}
System.out.println("the original arr2 is:"+Arrays.toString(arr2));
for(int i=0;i<arr1.length;i++) {
for(int j=0;j<arr2.length;j++) {
if(arr1[i]==arr2[j]) {
System.out.println("common element is:"+arr1[i]);
}
}
}
}
}
CommonStringBetweenTwoArrays
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class CommonStringBetweenTwoArrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
String arr1[]=new String[a];
String arr2[]=new String[b];
for(int i=0;i<a;i++) {
arr1[i]=sc.next();
}
for(int i=0;i<b;i++) {
arr2[i]=sc.next();
}
System.out.println("the original string is:"+Arrays.toString(arr2));
HashSet<String>set=new HashSet();
for(int i=0;i<arr1.length;i++) {
for(int j=0;j<arr2.length;j++) {
if(arr1[i].equals(arr2[j])) {
set.add(arr1[i]);
}
}
}
System.out.println("the common String value in both array is:"+(set));
}
}
TheAverageValueOfAnArrayOfIntegersExceptLargestAndSmallestValue
mport java.util.Arrays;
import java.util.Scanner;
public class ComputeTheAverageValueOfAnArrayOfIntegersExceptLargestAndSmallestValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int max=arr[0];
int min=arr[0];
float sum=arr[0];
for(int i=1;i<arr.length;i++) {
sum+=arr[i];
if(arr[i]>max) {
max=arr[i];
}
else if(arr[i]<min) {
min=arr[i];
}
float x=((sum-max-min)/(arr.length-2));
System.out.println("the average value of an array without max and min value is:"+x);
}
}
}
ConvertArrayListToAnArray
import java.util.*;
public class ConvertArrayListToAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String>sc=new ArrayList();
sc.add("obuli");
sc.add("purusothaman");
sc.add("k");
sc.add("19CS094");
sc.add("CSE");
String arr[]=new String[sc.size()];
sc.toArray(arr);
for(String a:arr) {
System.out.println(a);
}
}
}
ConvertArrayToArrayList
import java.util.Arrays;
import java.util.*;
public class ConvertArrayToArrayList {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
String arr[]=new String[a];
for(int i=0;i<a;i++) {
arr[i]=sc.next();
}
System.out.println("the orginal array is:"+Arrays.toString(arr));
ArrayList<String>list=new ArrayList(Arrays.asList(arr));
System.out.println("the converted array list is:"+list);
}
}
CopyAndSortAnArrayByIteratingArray
import java.util.Arrays;
import java.util.Scanner;
public class CopyAndSortAnArrayByIteratingArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
int arr2[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}System.out.println("the orginal array is:"+Arrays.toString(arr));
for(int i=0;i<arr.length;i++) {
arr2[i]=arr[i];
}
System.out.println("the copyied array is:"+Arrays.toString(arr2));
Arrays.sort(arr2);
System.out.println("the sorted array is:"+Arrays.toString(arr2));
}
}
DupliacteValuesInString
import java.util.Arrays;
import java.util.Scanner;
public class DupliacteValuesInString {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
String arr[]=new String[a];
for(int i=0;i<a;i++) {
arr[i]=sc.next();
}
System.out.println("the orginal string is:"+Arrays.toString(arr));
for(int i=0;i<arr.length;i++) {
for(int j=i+1;j<arr.length;j++) {
if((arr[i].equals(arr[j]))&&(i!=j)) {
System.out.println("the dupliacte string is:"+arr[j]);
}
}
}
}
}
FindAllPairsOfElementsInArrayWhosSumIsEqualToSpecifiedNumber
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class FindAllPairsOfElementsInArrayWhosSumIsEqualToSpecifiedNumber {
public static void main(String[] args) {
// TODO Auto-generated method stub
pairs(new int[]{1,2,3,4,5,5},10);
}
public static void pairs(int arr[],int findnumber) {
System.out.println("pairs of element and their sum:");
for(int i=0;i<arr.length;i++) {
for(int j=i+1;j<arr.length;j++) {
if(arr[i]+arr[j]==findnumber) {
System.out.println(arr[i]+"+"+arr[j]+"="+findnumber);
}
}
}
}
}
FindCommonElementsFromThreeSortedArrays
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class FindCommonElementsFromThreeSortedArrays {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int arr1[]=new int[a];
int arr2[]=new int[b];
int arr3[]=new int[c];
for(int i=0;i<a;i++) {
arr1[i]=sc.nextInt();
}
System.out.println("the arr1 is:"+Arrays.toString(arr1));
for(int i=0;i<b;i++) {
arr2[i]=sc.nextInt();
}
System.out.println("the arr2 is:"+Arrays.toString(arr2));
for(int i=0;i<c;i++) {
arr3[i]=sc.nextInt();
}
System.out.println("the arr3 is:"+Arrays.toString(arr3));
ArrayList<Integer>list=new ArrayList();
int x=0,y=0,z=0;
while(x<arr1.length && y<arr2.length && z<arr3.length) {
if(arr1[x]==arr2[y] && arr2[y]==arr3[z]) {
list.add(arr1[x]);
x++;
y++;
z++;
}
else if(arr1[x]<arr2[y]) {
x++;
}
else if(arr2[y]<arr3[z]) {
y++;
}
else
z++;
}
System.out.println("common elements in 3 arrays is:"+list);
}
}
FindDuplicateElementInArray
import java.util.Scanner;
public class FindDuplicateElementInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<arr.length;i++) {
for(int j=i+1;j<arr.length;j++) {
if((arr[i]==arr[j])&&(i!=j)) {
System.out.println("the duplicate element is:"+arr[j]);
}
}
}
}
}
FindEvenOddNumbersInArray
import java.util.Scanner;
public class FindEvenOddNumbersInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
int sum=0;
int sum1=0;
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
for(int i=0;i<arr.length;i++) {
if(arr[i]%2==0) {
sum+=arr[i];
}
System.out.println("the even number is:"+arr[i]+"sum is:"+sum);
//System.out.println("sum of even number is:"+sum);
else{
sum1+=arr[i];
}
System.out.println("the odd number is:"+arr[i]+"sum is:"+sum1);
}
}
}
FindMaxMinValuesInArray
import java.util.Arrays;
import java.util.Scanner;
public class FindMaxMinValuesInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the orginal array is:"+Arrays.toString(arr));
int max=arr[0];
int min=arr[0];
for(int i=0;i<a;i++) {
if(arr[i]>max)
max=arr[i];
if(arr[i]<min)
min=arr[i];
}
System.out.println("the max value in array:"+max);
System.out.println("the min value in array:"+min);
}
}
FindMissingNumberInArray
import java.util.Arrays;
import java.util.Scanner;
public class FindMissingNumberInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int arr[]=new int[] {1,2,3,4,6,7};
int totalnum;
totalnum=7;
System.out.println("the array is:"+Arrays.toString(arr));
int exc=totalnum*((totalnum+1)/2);
int num=0;
for(int i:arr) {
num+=i;
}
System.out.print(exc-num);
System.out.print("\n");
}
}
FindSecondLargestElementInArray
import java.util.Arrays;
import java.util.Scanner;
public class FindSecondLargestElementInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the original array is:"+Arrays.toString(arr));
Arrays.sort(arr);
int index=arr.length-1;
while(arr[index]==arr[arr.length-1]) {
index--;
}
System.out.println("the second largest value is:"+arr[index]);
}
}
FindSecondSmallestElementInArray
import java.util.Arrays;
import java.util.Scanner;
public class FindSecondSmallestElementInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int min=Integer.MAX_VALUE;
int secmin=Integer.MAX_VALUE;
for(int i=0;i<arr.length;i++) {
if(arr[i]==min) {
secmin=min;
}
else if(arr[i]<min) {
secmin=min;
min=arr[i];
}
else if(arr[i]<secmin) {
secmin=arr[i];
}
}
System.out.println("the second smallest elemnt is:"+secmin);
}
}
FindSmallestAndSecondSmallestElementsInArray
import java.util.Arrays;
import java.util.Scanner;
public class FindSmallestAndSecondSmallestElementsInArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int fst,sec,arrsize=arr.length;
if(arrsize<2) {
System.out.println("the array size is less than two");
return;
}
fst=sec=Integer.MAX_VALUE;
for(int i=0;i<arrsize;i++) {
if(arr[i]<fst) {
sec=fst;
fst=arr[i];
}
else if(arr[i]<sec&&arr[i]!=fst) {
sec=arr[i];
}
}
if(sec==Integer.MAX_VALUE)
System.out.println("No second smallest element");
else
System.out.println("the smallest element is:"+fst+" and second smallest elemt is:"+sec);
}
}
GetTheDiffrenceBetweenTheLargestAndSmallestValueInAnArray
import java.util.Arrays;
import java.util.Scanner;
public class GetTheDiffrenceBetweenTheLargestAndSmallestValueInAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int max=arr[0];
int min=arr[0];
for(int i=0;i<arr.length;i++) {
if(arr[i]>max) {
max=arr[i];
}
else if(arr[i]<min) {
min=arr[i];
}
}
System.out.println("the diffrence between max and min value is:"+(max-min));
}
}
GrindSolution
import java.util.Scanner;
public class GrindSolution {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int arr[][]=new int[a][b];
for(int i=0;i<10;i++) {
for(int j=0;j<10;j++) {
System.out.printf("%2d",arr[i][j]);
}
System.out.println();
}
}
}
IndexOfSpecificValue
import java.util.Scanner;
public class IndexOfSpecificValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("Index Position of 25 is:"+findIndex(arr,25));
}
public static int findIndex(int arr[],int pos) {
if(arr==null)
return -1;
int len=arr.length;
int i=0;
while(i<len) {
if(arr[i]==pos)
return i;
else
i=i+1;
}
return -1;
}
}
InsertAElementIntoAnArray
import java.util.Arrays;
import java.util.Scanner;
public class InsertAElementIntoAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the original array is:"+Arrays.toString(arr));
int index=2;
int value=100;
for(int i=arr.length-1;i>index;i--) {
arr[i]=arr[i-1];
}
arr[index]=value;
System.out.println("the updated array is:"+Arrays.toString(arr));
}
}
MoveAll0sFromTheEndOfAnArray
import java.util.Arrays;
import java.util.Scanner;
public class MoveAll0sFromTheEndOfAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the arr1 is:"+Arrays.toString(arr));
for(int n:arr) {
System.out.print(n+" ");
}
int j=0;
int l=arr.length;
for(int i=0;i<l;i++) {
if(arr[i]==0) {
i++;
}
else {
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j++;
}
}
while(j<arr.length) {
arr[j++]=0;
System.out.print("After moving 0's to the end of the array is:");
for(int n:arr) {
System.out.print(n+" ");
System.out.print("\n");
}
}
}
}
RemoveDuplicateElementFromArray
import java.util.Arrays;
import java.util.Scanner;
public class RemoveDuplicateElementFromArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
int unique=arr.length;
for(int i=0;i<unique;i++) {
for(int j=i+1;j<unique;j++) {
if(arr[i]==arr[j]) {
arr[j]=arr[unique-1];
unique--;
j--;
}
}
}
int arr1[]=Arrays.copyOf(arr,unique);
for(int i=0;i<arr1.length;i++) {
System.out.println(arr1[i]+" ");
}
System.out.println("the unique element array is:"+Arrays.toString(arr1));
}
}
RemoveDuplicateElementOfAGivenArrayAndReturnTheNewLengthOfTheArray
import java.util.Arrays;
import java.util.Scanner;
public class RemoveDuplicateElementOfAGivenArrayAndReturnTheNewLengthOfTheArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
System.out.println("the result is:"+result(arr));
}
public static int result(int arr[]) {
int index=1;
for(int i=1;i<arr.length;i++) {
if(arr[i]!=arr[i-1]) {
arr[index++]=arr[i];
}
}
return index;
}
}
RemoveSpecificElementFromArray
import java.util.Arrays;
import java.util.Scanner;
public class RemoveSpecificElementFromArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the orginal array is:"+Arrays.toString(arr));
int rem=1;
for(int i=rem;i<arr.length-1;i++) {
arr[i]=arr[i+1];
}
System.out.println("the removed elemnt is:"+Arrays.toString(arr));
}
}
ReverseAnArrayOfIntegerValue
import java.util.Arrays;
import java.util.Scanner;
public class ReverseAnArrayOfIntegerValue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the original array is:"+Arrays.toString(arr));
for(int i=0;i<arr.length/2;i++) {
int temp=arr[i];
arr[i]=arr[arr.length-i-1];
arr[arr.length-i-1]=temp;
}
System.out.println("the reversed array is:"+Arrays.toString(arr));
}
}
RotateAnArray
import java.util.Arrays;
import java.util.Scanner;
public class RotateAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int b=arr[arr.length-1],i;
for( i=arr.length-1;i>0;i--) {
arr[i]=arr[i-1];
arr[0]=b;
}
System.out.println("the rotated array is:"+Arrays.toString(arr));
}
}
SortNumericArrayAndAStringArray
import java.util.Arrays;
import java.util.Scanner;
public class SortNumericArrayAndAStringArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr1[]=new int[a];
String arr2[]= {
"java",
"python",
"c",
"c++",
"php"
};
for(int i=0;i<a;i++) {
arr1[i]=sc.nextInt();
}
System.out.println("the orginal int array is:"+Arrays.toString(arr1));
Arrays.sort(arr1);
System.out.println("the sorted int array is:"+Arrays.toString(arr1));
System.out.println("the orginal string array is:"+Arrays.toString(arr2));
Arrays.sort(arr2);
System.out.println("the sorted string array:"+Arrays.toString(arr2));
}
}
SumOfAnArray
import java.util.Arrays;
import java.util.Scanner;
public class SumOfAnArray {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int arr[]=new int[a];
for(int i=0;i<a;i++) {
arr[i]=sc.nextInt();
}
System.out.println("the array is:"+Arrays.toString(arr));
int sum=0;
for(int i=1;i<=arr.length;i++) {
sum+=i;
}
System.out.println("the sum of the array is:"+sum);
}
}