1. Write a program to display sum of array elements at run-time
package pow;
import java.util.Scanner;
public class SumArry {
public static void main(String[] args) {
System.out.println("enter size of array");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
System.out.println("Enter "+s+" element of 1st array");
int arr1[]=new int[s];
for(int i=0;i<s;i++)
{
arr1[i]=sc.nextInt();
}
System.out.println("Enter "+s+" element of 2nd array");
int arr2[]=new int[s];
for(int i=0;i<s;i++)
{
arr2[i]=sc.nextInt();
}
int sumArr[]=new int[s];
for(int i=0;i<s;i++){
sumArr[i]=arr1[i]+arr2[i];
System.out.print(sumArr[i]+" ");
}}}
2. Write a program to find minimum and maximum element in an array.
package pow;
import java.util.Scanner;
public class Armstrongp {
public static void main(String[] args) {
int i;
System.out.println("enter size of array");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
System.out.println("Enter "+s+" element of 1st array");
int arr1[]=new int[s];
for( i=0;i<s;i++)
{
arr1[i]=sc.nextInt();
}
int max= arr1[0];
int min= arr1[0];
for(i=0;i<s;i++)
{
if(arr1[i]>max)
max=arr1[i];
if(arr1[i]<min)
min =arr1[i];
}
System.out.print("Maximum number: "+max+" minimum number: "+min);
}
}
I am not responsible if any thing goes wrong due to these programs
If anyone not getting these programs just fell free to call.
1 Comments
Super mama
ReplyDelete