ARRAY PROGRAMS
[Link] a program to print the 2nd and 4th elements in the given array?
output should be 3.
int[] intArray = new int[]{1,3,2,6,5,4};
[Link] a program to print the 2nd repeated element in the given array.
output should be 3.
int[] intArray = new int[]{1,1,3,1,2,6,3,5,4};
[Link] a program to check
1) Arrays have same elements at each position.
2) Arrays have the same elements but position of elements are different.
3) Arrays have the same unique elements.
Given Arrays:
Integer[] a1 = {1,2,3,2,1};
Integer[] a2 = {1,2,3};
Integer[] a3 = {1,2,3,4};
Integer[] a4 = {1,2,3};
Integer[] a5 = {1,3,2};
[Link] the correct way of initializing a multidimensional array below.
a)int[2][]x={(1,2),(3,4,5)};
b)int[][]x={(1,2),(3,4,5)};
c)int[][]x={1,2.3,4,5};
1
ARRAY PROGRAMS
d)All
[Link] is the output the following code?
public class Test{
public static void main(String[] args)
{
char[] charArr = new char[5];
for(int i=0;i<[Link];++i)
{
charArr[i]='i';
[Link](charArr[i]+" ");
}
}
}
a)i i i i i
b)0 1 2 3 4
c)1 2 3 4 5
d)CE:Variable must provide either dimension expressings of an array initialization.
[Link] a program to find Mean of odd index numbers.
ex:Array with more than 3 elements eg:{2,4,25,26,78,42}
2
ARRAY PROGRAMS
[Link] a program to find common elements between two arrays.
input:['g','y','p','q','r'],['q','t','i','p']
output:q,p
[Link] of an [Link] a program on it?
[Link] largest element in an array?
[Link] two unsorted arrays and sort them.
[Link] odd and even positions in an array?
[Link] a program to print swap two numbers without using third variable.
[Link] a program to print duplicate elements in a given array
[Link] a program to merge two arrays.
[Link] a program to print even index and odd index elements in an array.
[Link] is the output of this program?
class evaluate{
public static void main(String args[])
{
3
ARRAY PROGRAMS
intarr[] = new int[]{0,1,2,3,4,5,6,7,8,9}
int n=6;
n=arr[arr[n]/2];
[Link](arr[n]/2);
}
}
a)3
b)0
c)6
d)1
[Link] of the following is valid declaration for array?
[Link][] startsWith[];
int[] score;
char[8] dist;
school students[];
school students[5];
a)1,2,4
b)2,4,5
c)2,3,4
d)All are correct.
1.W.A.P to remove duplicate number in an array.
4
ARRAY PROGRAMS
18.W.A.P to find duplicate elements in the given array and print their sum.
Array = {5,3,4,6,7,5,3,2,1}
Duplicate elements : 5,3
sum of duplicate elements :5+3=8.
19.W.A.P to find the 2nd highest value from array.
I/P : [5,8,6,11,4,6,9]
o/p : 9.
[Link] Metti{
public static void main(String[] args)
{
int a[] =(10,20,3);
[Link]([Link]);
}
}
[Link] Metti{
public static void main(String[] args)
{
float f1=10.20f;
float f2=10.20f;
[Link](f1==f2);
}
5
ARRAY PROGRAMS
}
22.#include<stdio.h>
int main()
{
int arr[] = {12,13,14,15,16};
printf("%d,%d,%d\n",sizeof(arr),sizeof(*arr),sizeof(arr[0]))
return 0;
}
a)10,2,4
b)20,4,4
c)16,2,2
d)20,2,2
23.#include<stdio.h>
int main()
{
Static char *s[] = {"black","White","pink","violet");
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s",**p+1);
return 0;
}
6
ARRAY PROGRAMS
[Link] 2 arrays,find which numbers from first array is not present in second
array,Eg[1,4,2,5,6] and [3,6,2,7,9] ans-1,4,5.
[Link] a program where the same array is find in the array?
[Link] a program to find largest and smallest numbers in an given unsorted array.
[Link] to get the matching elements in an integer array?
[Link] a program to find the smallest even number in a given array.
For ex:
If the input array [10,40,50,6,3,100,5,1,200] then the output should be 6 is smallest
even number in the array.
[Link] a program to find out if there are any consecutive numbers in a given array,
and print the sequence
example- i/p:{7,4,6,9,1,2,3,4,30,40,32}
o/p:{1,2,3,4}
[Link] a program to read the age of a few [Link] then based on their age,print
count of childern and adults?
example- i/p:{10,20,30,40,15,8,50,60}
o/p: Children count:3
Adult count: 5
7
ARRAY PROGRAMS
[Link] a program to reverse a given array by swapping the elements within it,
without using a second array and without printing it from last to first
example-if user enters the i/p array A as{10,20,30,40,50,60,70}
when you print it o/p should be {70,60,50,40,30,20,10}
[Link]
public class Program12 {
public static void main(String[] args) {
int [] x= {10,20,70,60,40};
int highest=x[0];
int lowest=x[0];
for(int i:x) {
if(i>highest) {
highest = i;
}
if(i<lowest) {
lowest=i;
}
}
[Link](highest + " is highest number ");
[Link](lowest + " is lowest number ");
}
}
8
ARRAY PROGRAMS
[Link] a program for the below requirements.
Input :{-3,-2,-1,3,1};
Output:{-3,-2,-1,1,3};
Without changing the place of negative number we need to change the positions of
the positive number.
[Link] the array without changing -ve number Index
Test case1:
I/P a[] = {11,16,-2,-4,7,8};
o/p a[] = {7,8,-2,-4,11,16};
Test case2:
I/p a[] = {-6,4,2,-1,9};
o/p a[] = {-6,2,4,-1,9};
[Link] a program to print 2nd largest element in an array.
[Link] of an array in descending order.
[Link] an element in an array and remove the element in an array?