# Arrays Solutions ICSE Class 10 Computer Applications

Get ICSE Arrays Solutions Class 10. It will help you to make good preparation before attending the ICSE Board exam. We have provided you with Arrays Solutions class 10 to score good marks in your exam.

In ICSE Class 10, Arrays Solutions is compulsory to score good marks in computer applications. Students Who are planning to score higher marks in class 10 should practice ICSE Arrays Solutions class 10.

## ICSE Arrays Solutions for class 10 Computer Application

1. What are arrays?
Ans. Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type.

2. How do you declare single and 2-dimensional arrays?
Ans. General syntax of declaring a single dimensional array:
type array-name [ ] = new type [size];
General syntax of declaring a two dimensional array:
type array-name[][]=new type[row-size][column-size];

3. How do you create memory spaces for single and 2-dimensional arrays?
Ans. In a single dimensional array memory is allocated in contiguous spaces. For 2 dimensional arrays also memory are allocated in contiguous memory locations, however they are logically arranged in the form of rows and columns.

4. How do you initialise single and 2-dimensional arrays? Explain with examples.
Ans. The general form of Initialisation of single dimensional array is:
type array-name[ ]={ list of values };
For example,
int n [ ] = {5, 12, 7};
The general form of Initialisation of two dimensional array is:
type array-name[ ][ ]={ {list of values},{list of values},{list of values}… };
For example,
int a[][]={{5,1,3},{7,2,6}};

5. With the help of an example, show how arrays in Java are dynamic in nature.
Ans. Java arrays are dynamic in nature:
For example,
int n;
Scanner sc=new Scanner (System.in);
System.out.println(“Enter the size;”);
n=sc.nextInt(); //Enter the size from the user
int arr [ ]=new int[n]; //declare an array of size (dynamic)
As you can see the memory for the array arr is created only after taking the size ‘n’ from the user.

6. How do you determine the length of an array?
Ans. To determine the length of an array, the following syntax may be used:
<array-name>.length
The length is the property of an array that provides the number of elements in an array.

7. With the help of an example show how arrays are passed to a function as Call by Reference.
Ans. The following illustrates how are arrays passed as call by reference:
class ArrayDemo
{
//Method to double the value of each element in the array.
static void doubleIt(int a[])
{
for(int i=0; i<a.length; i++)
{
a[i]=2*a[i];
}
}
public static void main (String args[])
{
int a []={4,5,12,7,8,3};
System.out.println(“Original Array…”);
for (inti=0;i<a. length;i++)
System.out.print(a[i]+“/t”);
doubleIt(a); // this is how you pass an array as
//parameter.
System.out.println (“InUpdated Array…”);
for(int i=0;i<a.length;i++)
System.out.print(a[i]+“\t”);
}
}
Output when main( ) is executed will be,
Original Array….
4 5 12 7 8 3
Updated Array…
8 10 24 14 16 6

8. Explain:
i. Linear Search
ii. Binary Search
Ans.
i. Linear search or sequential search is a method for finding a particular value in a list, that consists of checking everyone of its elements, one at a time and in sequence, until the desired one is found.
ii. Binary search in Java using divide and conquer technique. A binary search or half-interval search algorithm finds the position of a specified value(the input“key”) within a sorted array.

9. Compare Selection Sorting and Bubble sorting.
Ans.

10. What is the difference between one-dimensional and two-dimensional arrays?
Ans. A one-dimensional array is a list of variables with the same datatype, whereas the two- Dimensional array is ‘array of arrays’ having similar data types.

11. With the help of an example, show how a two-dimensional float type array of size 3×4 can be initialised.
Ans. float a[]=new float[3][4];

12. Why do you think in most cases nested loops are required to access the individual elements of a 2-dimensional array?
Ans. This is to traverse through each element of a 2D array through each row and column.

13. How do you determine the size of a two dimensional array?
Ans. No. Of elements in a 2D array is the generally the product of the no. Of rows and no. Of columns.

i. Gives a concise code as declaration, allocation of space and Initialisation can be done in a single line.
ii. Java arrays are dynamic, unlike other languages like C, C++.
iii. It is possible to directly access any element, provided the index is known. Thus making manipulation easy.
i. Arrays allows you to store elements of only one data type, i.e., only homogenous data can be stored, thus data of heterogenous data type cannot be stored, which is often required by a programmer.
ii. Arrays always require contiguous free memory location to be allocated for storing elements. But there may be situations when the available memory is discrete in nature and therefore array cannot be used to efficiently use the memory.
iii. Careful design is required to make sure that large lists of data can be stored.

1. What is the difference between these two statements:
i. int sum[]=new int[10] ii. sum[1]=10;
Ans. The first statement declares an integer array of size 10 having the name ‘sum’. The second statement initialises the second element of the array ‘sum’ with 10.

2. Write the correct form of the following arrays:
i. A1(2) ii. Name[2,5]
iii. Roll[2;] iv. Matrix(5)(5)
Ans. i. A1[2]
ii. Name[2][5]
iii. Roll[2]
iv. Matrix[5][5]

3. Write the value of individual array element.
i. int c[]={78,23,45,12,16};
ii. int p[][]={{1,1},{3,3},{5,5},{7,7}};
Ans.
i. c[0]=78, c[1]=23, c[2]=45, c[3]=12, c[4]=16
ii. p[0][0]=1, p[0][1]=1, p[1][0]=3, p[1][1]=3, p[2][0]=5, p[2][1]=5, p[3][0]=7, p[3][1]=7

4. Give the proper array declaration for the following:
i. Declare an integer array, which can hold 25 values.
ii. Declare a two dimensional array called mat 3×4 of integer.
iii. Declare and initialise a two dimensional array of size 5×5 to 0.
Ans. i. int a[]=new int[25];
ii. int mat[][]=new int[3][4];
iii. int a[][]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};

5. What will be the output of the following program:
class Output
{
public static void main(String args[])
{
int a[]={6,5,4,3,2,1};
int x;
for(x=5;x>=0;x–)
{
System.out.println(a[x]);
}
}
}
Ans. Output:
1
2
3
4
5
6

6. What will be the output of the following program:
class First
{
public static void main(String args[])
{
int a[]={5,1,15,20,25};
int i,j;
int m;
i=++a[1];
j=a[2]++;
m=a[i++];
System.out.print(i+“ ”+j+“ ”+m);
}
}
Ans. Output:
3  15  16

7. What will be the output of the following program, when Method invoke() is called:
public class StringArray
{
void change(String arr[])
{
for(int i=0;i<arr.length;i++)
{
arr[i]=arr[i].substring(0,1).toUpperCase()+arr[i].substring(1);
}
}
void invoke()
{
String ar[]={“kolkata”,“gangtok”,“banglore”};
for(int i=0;i<ar.length;i++)
System.out.println(ar[i]);
change(ar);
for(int i=0;i<ar.length;i++)
System.out.println(ar[i]);
}
}
Ans. Output:
kolkata
gangtok
banglore
Kolkata
Gangtok
Banglore

8. What will be the output of the following program:
class Output
{
public static void main(String args[])
{
int a,b=0;
int c[]={1,2,3,4,5,6,7,8,9,10};
for(a=0;a<10;a++)
{
if(a%2==0)
b+=c[a];
}
System.out.print(b);
}
}
In what statement, state what the above program is doing?
Ans. Output:
25

9. Find the syntax error(s), if any in the following program.
Class First
{
public static void main(String args[])
{
int sum[2,4];
for(i=0;i<2;i++)
{
for(j=0;j<=3;j++)
{
System.print(sum);
}
}
}
}
Ans.
class First
{
public static void main(String args[])
{
int sum[][]=new int[2][4];
for(i=0;i<2;i++)
{
for(j=0;j<=3;j++)
{
System.out.print(sum[i][j]+“ ”);
}
}
}
}

10. Identify error(s), if any, in the following program.
class First
{
public static void main(String args[])
{
int i;
int a[6]={0,1,8,7,6,4};
for(i=0;i<=a.length();i++)
System.out.println(a[i]);
}
}
Ans.
class First
{
public static void main(String args[])
{
int i;
int a[]={0,1,8,7,6,4};
for(i=0;i<a.length;i++)
System.out.println(a[i]);
}
}

SECTION B

1. Write a program to input 10 numbers into an integer array and find the sum of all numbers in it.

Ans.
import java.util.*;
class Sol1
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,s=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
s+=a[i];
System.out.println(“Sum=”+s);
}
}

2. Write a program to input 10 numbers into an integer array and find the sum of even and odd numbers separately.

Ans.
import java.util.*;
class Sol2
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,se=0,so=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(a[i]%2==0)
se+=a[i];
else
so+=a[i];
}
System.out.println(“Sum of even numbers=”+se);
System.out.println(“Sum of odd numbers=”+so);
}
}

3. Write a program to input 10 numbers into an integer array and print those numbers which are less than its average.

Ans.
import java.util.*;
class Sol3
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,s=0;
float av;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(a[i]%2==0)
s+=a[i];
}
av=(float)s/10;
System.out.println(“Numbers less than average:”);
for(i=0;i<10;i++)
{
if(a[i]<av)
System.out.print(a[i]+“ ”);
}
}
}

4. Write a program to input 10 numbers into an integer array and find the sum of prime numbers only.

Ans.
import java.util.*;
class Sol4
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,s=0,j,c;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
c=0;
for(j=1;j<=a[i];j++)
{
if(a[i]%j==0)
c++;
}
if(c==2)
s+=a[i];
}
if(s>0)
System.out.println(“Sum of prime numbers:”+s);
else
System.out.println(“No prime numbers found”);
}
}

5. Write a program to input 10 numbers into an integer array and check whether all numbers are 3-digit numbers or not.

Ans.
import java.util.*;
class Sol5
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i;
boolean f=true;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(!(a[i]>=100 && a[i]<=999))
f=false;
}
if(f)
System.out.println(“All are 3 digit numbers”);
else
System.out.println(“All are not 3 digit numbers”);
}
}

6. Write a program to input 10 numbers into an integer array and check whether all numbers in it are same or not.

Ans.
import java.util.*;
class Sol6
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i;
boolean f=true;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(a[i]!=a[0])
f=false;
}
if(f)
System.out.println(“All are same”);
else
System.out.println(“All are not same”);
}
}

7. Write a program to input 10 numbers into an integer array and check whether they are in ascending order or not.

Ans.
import java.util.*;
class Sol7
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i;
boolean f=true;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<9;i++)
{
if(a[i]>a[i+1])
f=false;
}
if(f)
System.out.println(“All are in ascending order”);
else
System.out.println(“All are not in ascending order”);
}
}

8. Write a program to input 10 numbers into an integer array and find the position of the largest and the smallest number.

Ans.
import java.util.*;
class Sol8
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,l=0,s=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
l=s=a[0];
for(i=1;i<10;i++)
{
if(a[i]>l)
l=a[i];
if(a[i]<s)
s=a[i];
}
for(i=0;i<10;i++)
{
if(a[i]==l)
System.out.println(“Position of largest number:”+i);
if(a[i]==s)
System.out.println(“Position of smallest number:”+i);
}
}
}

9. Write a program to input 10 numbers into an integer array and interchange the largest number with the smallest number within the array and print the modified array. Assume that there is only one largest and smallest number.

For example, if array contains

After interchange it should have the elements arranged as:

Ans.
import java.util.*;
class Sol9
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,l=0,s=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
l=s=a[0];
for(i=1;i<10;i++)
{
if(a[i]>l)
l=a[i];
if(a[i]<s)
s=a[i];
}
for(i=0;i<10;i++)
{
if(a[i]==l)
a[i]=s;
else if(a[i]==s)
a[i]=l;
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

10. Write a program to input 10 numbers into an integer array and replace all prime numbers in it (if any) by 0 and print the modified array.

For example, if the array contains the following elements:

After replacing the prime numbers with 0 the modified array should have the elements as:

Ans.
import java.util.*;
class Sol10
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,c;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
c=0;
for(j=1;j<=a[i];j++)
{
if(a[i]%j==0)
c++;
}
if(c==2)
a[i]=0;
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

11. Write a program to input 10 numbers into an integer array and print the smallest prime number in the array.

Ans.
import java.util.*;class Sol11
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,c,s=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
c=0;
for(j=1;j<=a[i];j++)
{
if(a[i]%j==0)
c++;
}
if(c==2)
{
if(s==0)
s=a[i];
if(a[i]<s)
s=a[i];
}
}
if(s>0)
System.out.println(“Smallest prime number:”+s);
else
System.out.println(“No prime number found”);
}
}

12. Write a program to input 10 numbers into an integer array and print the position of the second largest number in it.

Ans.
import java.util.*;
class Sol12
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,l=0,sl=0,p=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
l=a[0];
for(i=1;i<10;i++)
{
if(a[i]>l)
l=a[i];
}
for(i=0;i<10;i++)
{
if(a[i]!=l)
{
if(sl==0)
{
sl=a[i];
p=i;
}
if(a[i]>sl)
{
sl=a[i];
p=i;
}
}
}
System.out.println(“Position of second largest:”+p);
}
}

13. Write a program to input 10 numbers into an integer array and arrange the numbers in descending order using Linear Sorting technique.

Ans.
import java.util.*;
class Sol13
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

14. Write a program to input 10 numbers into a float type array and arrange the numbers in descending order using Bubble Sorting technique.

Ans.
import java.util.*;
class Sol14
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=9;i>0;i–)
{
for(j=0;j<i;j++)
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

15. Write a program to input 10 numbers into an integer array and reverse the array and print the modified array.
For example, if array contains

After reversal it should have the elements arranged as:

Ans.
import java.util.*;
class Sol15
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<5;i++)
{
t=a[i];
a[i]=a[9-i];
a[9-i]=t;
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+” “);
}
}
}

16. Write a program to input 10 numbers into an integer array and interchange the consecutive elements in it. That is, interchange a[0] with a[1], a[2] with a[3], a[4] with a[5] …
For example, if array contains

After interchange it should have the elements arranged as:

Ans.
import java.util.*;
class Sol16
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<9;i+=2)
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

17. Write a program to input 10 numbers into an integer array and find the frequency of the largest number.
For example, if array contains

Output should be:
Frequency of largest number = 3

Ans.
import java.util.*;
class Sol17
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,l=0,c=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<9;i++)
{
if(a[i]>l)
l=a[i];
}
for(i=0;i<10;i++)
{
if(a[i]==l)
c++;
}
System.out.print(“Frequency of the largest:”+c);
}
}

18. Write a program to input 10 numbers into an integer array and input a position. Now delete the element at that position by shifting the rest of the numbers to the left and insert a 0 at the end.

Ans.
class Sol18
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,p;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
System.out.println(“Enter the position to delete:”);
p=sc.nextInt();
for(i=p;i<9;i++)
{
a[i]=a[i+1];
}
a[9]=0;
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

19. Write a program to input 10 numbers into an integer array and input a number and a position. Now insert the number at that position by shifting the rest of the numbers to the right. The last element is therefore removed from the array.

Ans.
import java.util.*;
class Sol19
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,p,n;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
System.out.println(“Enter the number to insert:”);
n=sc.nextInt();
System.out.println(“Enter the position to insert:”);
p=sc.nextInt();
for(i=9;i>p;i–)
{
a[i]=a[i-11];
}
a[p]=n;
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

20. Write a program to input 10 positive or negative numbers (no zero) into an integer array and shift all positive numbers to the beginning of the array and negative numbers to the end of the array; without changing the order of the numbers.

Ans.
import java.util.*;
class Sol20
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=9;i>0;i–)
{
for(j=0;j<i;j++)
{
if(a[j]<0 && a[j+1]>0)
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

21. Write a program to input 10 numbers into an integer array and shift all even numbers to the beginning of the array and odd numbers to the end of the array; without changing the order of the numbers.

Ans.
import java.util.*;
class Sol21
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,t;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=9;i>0;i–)
{
for(j=0;j<i;j++)
{
if(a[j]%2!=0 && a[j+1]%2==0)
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println(“Modified Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

22. Write a program to input 10 numbers into an integer array and print those single-digit positive numbers which are not present in the array.
For example, if array contains

Output should be:
1, 2, 4, 5, 6

Ans.
import java.util.*;
class Sol22
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j;
boolean f;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<=9;i++)
{
f=false;
for(j=0;j<10;j++)
{
if(a[j]==i)
f=true;
}
if(f==false)
System.out.println(i);
}
}
}

23. Write a program to input 10 numbers into an integer array and find the frequency of each two-digit numbers present in it.
For example, if array contains

Output should be:
Frequency of 12 = 3
Frequency of 16 = 1
Frequency of 24 = 1
Frequency of 34 = 2
Frequency of 99 = 2

Ans.
import java.util.*;
class Sol23
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,f;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=10;i<=99;i++)
{
f=0;
for(j=0;j<10;j++)
{
if(a[j]==i)
f++;
}
if(f>0)
System.out.println(“Frequency of “+i+” is=”+f);
}
}
}

24. Write a program to input 10 numbers into an integer array and find the frequency of each number present in it.

Ans.
import java.util.*;
class Sol24
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,f,c;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
c=f=0;
for(j=0;j<10;j++)
{
if(a[i]==a[j])
{
c++;
if(j<i)
f=1;
}
}
if(f==0)
System.out.println(“Frequency of “+a[i]+” is=”+c);
}
}
}

25. Write a program to input 10 numbers into an integer array and print the number having maximum frequency assume that there is only one number having maximum frequency.
For example, if array contains

Output should be:
Number having maximum frequency=12

Ans.
import java.util.*;
class Sol25
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,max=0,n=0,c;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
c=0;
for(j=0;j<10;j++)
{
if(a[i]==a[j])
c++;
}
if(c>max)
{
max=c;
n=a[i];
}
}
System.out.println(“Number having maximum frequency=”+n);
}
}

26. Write a program to input 10 numbers into an integer array and store only the even numbers into another array and display it.

Ans.
import java.util.*;
class Sol26
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,b[]=new int[10],c=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(a[i]%2==0)
b[c++]=a[i];
}
System.out.println(“Resultant Array:”);
for(i=0;i<c;i++)
{
System.out.print(b[i]+ “ ”);
}
}
}

27. Write a program to input 10 numbers into an integer array and store only the unique numbers into another array and display it.
For example, if the given array contains

Ans.
import java.util.*;
class Sol27
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,b[]=new int[10],c=0,j,p=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
p=0;
for(j=0;j<10;j++)
{
if(a[i]==a[j])
p++;
}
if(p==1)
b[c++]=a[i];
}
System.out.println(“Resultant Array:”);
for(i=0;i<c;i++)
{
System.out.print(b[i]+ “ ”);
}
}
}

28. Write a program to input 10 numbers into an integer array and store each number only once into another array irrespective of the number of times it is present in the array.
For example, if the given array contains

Ans.
import java.util.*;
class Sol28
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,b[]=new int[10],c=0,j,p=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
p=0;
for(j=i+1;j<10;j++)
{
if(a[i]==a[j])
p++;
}
if(p==0)
b[c++]=a[i];
}
System.out.println(“Resultant Array:”);
for(i=0;i<c;i++)
{
System.out.print(b[i]+“ ”);
}
}
}

29. Write a program to input 10 numbers into an integer array and store all even numbers into one array and all odd numbers into another array. Display all the three arrays.

Ans.
import java.util.*;
class Sol29
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,b[]=new int[10],c[]=new int[10];
int ib=0,ic=0;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<10;i++)
{
if(a[i]%2==0)
b[ib++]=a[i];
else
c[ic++]=a[i];
}
System.out.println(“Resultant Array Even No.s:”);
for(i=0;i<ib;i++)
{
System.out.print(b[i]+“ ”);
}
System.out.println(“Resultant Array Odd No.s:”);
for(i=0;i<ic;i++)
{
System.out.print(c[i]+“ ”);
}
}
}

30. Write a program to input numbers into a 5×5 integer matrix and find the sum of all numbers in it.

Ans.
import java.util.*;
class Sol30
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
s+=a[i][j];
}
}
System.out.print(“Sum=”+s);
}
}

31. Write a program to input numbers into a 5×5 integer matrix and print the largest and smallest number from it.

Ans.
import java.util.*;
class Sol31
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,l=0,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==0 && j==0)
l=s=a[i][j];
else
{
if(a[i][j]>l)
l=a[i][j];
if(a[i][j]<s)
s=a[i][j];
}
}
}
System.out.print(“Largest=”+l);
System.out.print(“Smallest=”+s);
}
}

32. Write a program to input numbers into a 5×5 integer matrix and interchange the largest number with the smallest number and display the modified matrix.

Ans.
import java.util.*;
class Sol32
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,l=0,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==0 && j==0)
l=s=a[i][j];
else
{
if(a[i][j]>l)
l=a[i][j];
if(a[i][j]<s)
s=a[i][j];
}
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]==l)
a[i][j]=s;
else if(a[i][j]==s)
a[i][j]=l;
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(“\t”+a[i][j]);
}
System.out.println();
}
}
}

33. Write a program to input numbers into a 5×5 integer matrix and find the sum of each row separately.

Output:
Sum of row 1 = 13
Sum of row 2 = 32
Sum of row 3 = 26
Sum of row 4 = 27
Sum of row 5 = 16

Ans.
import java.util.*;
class Sol33
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
s=0;
for(j=0;j<5;j++)
{
s+=a[i][j];
}
System.out.println(“Sum of row”+(i+1)+ “=” +s);
}
}
}

34. Write a program to input numbers into a 5×5 integer matrix and find the sum of each column separately.

Output:
Sum of column 1 = 17
Sum of column 2 = 22
Sum of column 3 = 30
Sum of column 4 = 28
Sum of column 5 = 17

Ans.
import java.util.*;
class Sol34
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
s=0;
for(j=0;j<5;j++)
{
s+=a[j][i];
}
System.out.println(“Sum of column” +(i+1)+ “= “+s);
}
}
}

35. Write a program to input numbers into a 5×5 integer matrix and check whether all numbers in it are even numbers or not.
Example 1:
If the given matrix is:

Output:
All are even numbers.
Example 2:
If the given matrix is:

Output:
All are not even numbers.

Ans.
import java.util.*;
class Sol35
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]%2!=0)
f=1;
}
}
if(f==0)
System.out.println(“All are even numbers”);
else
System.out.println(“All are not even numbers”);
}
}

36. Write a program to input numbers into a 5×5 integer matrix and print the largest and the smallest number among both the diagonals.

Ans.
import java.util.*;
class Sol36
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,l=0,s=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
l=s=a[0][0];
for(i=0;i<5;i++)
{
if(a[i][i]>l)
l=a[i][i];
if(a[i][i]<s)
s=a[i][i];
if(a[i][4-i]>l)
l=a[i][4-i];
if(a[i][4-i]<s)
s=a[i][4-i];
}
System.out.println(“Largest=”+l);
System.out.println(“Smallest=”+s);
}
}

37. Write a program to input numbers into a 5×5 integer matrix and sort the major diagonal elements in descending order.

Ans.
import java.util.*;
class Sol37
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,t;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i][i]<a[j][j])
{
t=a[i][i];
a[i][i]=a[j][j];
a[j][j]=t;
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(“\t”+a[i][j]);
}
System.out.println();
}
}
}

38. Write a program to input numbers into a 5×5 integer matrix and sort the minor diagonal elements in ascending order.

Ans.
import java.util.*;
class Sol38
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,t;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i][4-i]<a[j][4-j])
{
t=a[i][4-i];
a[i][4-i]=a[j][4-j];
a[j][4-j]=t;
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(“\t”+a[i][j]);
}
System.out.println();
}
}
}

39. Write a program to input numbers into a 5×5 integer matrix and sort elements of each row in ascending order.

Ans.
import java.util.*;
class Sol39
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,t,r;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(r=0;r<5;r++)
{
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[r][i]>a[r][j])
{
t=a[r][i];
a[r][i]=a[r][j];
a[r][j]=t;
}
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(“\t”+a[i][j]);
}
System.out.println();
}
}
}

40. Write a program to input numbers into a 5×5 integer matrix and sort elements of each column in descending order.

Ans.
import java.util.*;
class Sol40
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,t,c;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(c=0;c<5;c++)
{
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i][c]<a[j][c])
{
t=a[i][c];
a[i][c]=a[j][c];
a[j][c]=t;
}
}
}
}
System.out.println(“Sorted Array:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(“\t”+a[i][j]);
}
System.out.println();
}
}
}

41. Write a program to input numbers into a 5×5 integer matrix and print the number having maximum frequency.

Ans.
import java.util.*;
class Sol41
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,t,r,c,p,max=0,n=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(r=0;r<5;r++)
{
for(c=0;c<5;c++)
{
p=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[r][c]==a[i][j])
p++;
}
}
if(p>max)
{
max=p;
n=a[r][c];
}
}
}
System.out.println(“No. having maximum frquency=:”+n);
}
}

42. Write a program to input numbers into a 5×5 integer matrix and print the frequency of each number.

Ans.
import java.util.*;
class Sol42
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,l=0,s=0,x,c;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==0 && j==0)
l=s=a[i][j];
else
{
if(a[i][j]>l)
l=a[i][j];
if(a[i][j]<s)
s=a[i][j];
}
}
}
for(x=s;x<=l;x++)
{
c=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(x==a[i][j])
c++;
}
}
if(c>0)
System.out.println(“Frequency of”+x+“is=”+c);
}
}
}

43. Write a program to read in a 5×5 matrix and then ask for an input of a number and search its position in the matrix. If found, print the indices where it is found, otherwise print “Not Found”.

Ans.
import java.util.*;
class Sol43
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0,n;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println(“Enter the number to search:”);
n=sc.nextInt();
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]==n)
{
System.out.println(“Position present at i=”+i+ “j=”+j);
f=1;
}
}
}
if(f==0)
}
}

44. Write a program to input numbers into a 5×5 integer matrix and check whether it is a unit matrix or not. Unit matrix is such a matrix whose major diagonal elements are 1 and the rest are 0.

Ans.
import java.util.*;
class Sol44
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==j)
{
if(a[i][j]!=1)
f=1;
}
else
{
if(a[i][j]!=0)
f=1;
}
}
}
if(f==0)
System.out.println(“Unit Matrix”);
else
System.out.println(“Not a Unit Matrix”);
}
}

45. Write a program to input numbers into a 5×5 integer matrix and check whether it is a diagonal matrix or not. Diagonal matrix is such a matrix whose major diagonal elements are non-zeroes and rest of the elements are zeroes.

Ans.
import java.util.*;
class Sol45
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==j)
{
if(a[i][j]==0)
f=1;
}
else
{
if(a[i][j]!=0)
f=1;
}
}
}
if(f==0)
System.out.println(“Diagonal Matrix”);
else
System.out.println(“Not a Diagonal Matrix”);
}
}

46. Write a program to input numbers into a 5×5 integer matrix and find it’s transpose. The transpose of a matrix is a new matrix whose rows are the columns of the original. (This makes the columns of the new matrix the rows of the original). Here is a matrix and its transpose:
The superscript “T” means transpose.

Ans.
import java.util.*;
class Sol46
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j;
int T[][]=new int[5][5];
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
T[i][j]=a[j][i];
}
}
System.out.println(“Transpose Matrix:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
System.out.print(T[i][j]+“\t”);
}
System.out.println();
}
}
}

47. Write a program to input numbers into a 5×5 integer matrix and check whether it is a symmetric matrix or not. Symmetric matrix is such a square matrix whose row elements are exactly same as column elements. Thus a symmetric matrix is a square matrix that is equal to its transpose.

Ans.
import java.util.*;
class Sol47
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]!=a[j][i])
f=1;
}
}
if(f==0)
System.out.println(“Symmetric Matrix”);
else
System.out.println(“Not a Symmetric Matrix”);
}
}

48. Write a program to input numbers into a 5×5 integer matrix and check whether it is a Lower Triangular Matrix or not. Lower Triangular Matrix is such a matrix whose elements above the major diagonal are zeroes and below the major diagonal are non-zeroes.

Ans.
import java.util.*;
class Sol48
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j>i)
{
if(a[i][j]!=0)
f=1;
}
else if(j<i)
{
if(a[i][j]==0)
f=1;
}
}
}
if(f==0)
System.out.println(“ Lower Triangular Matrix”);
else
System.out.println(“Not a Lower Triangular Matrix”);
}
}

49. Write a program to input numbers into two – 3×3 integer matrices and find their sum and store it in the third matrix.

Ans.
import java.util.*;
class Sol49
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[3][3],b[][]=new int[3][3],c[][]=new int[3][3],i,j;
System.out.println(“Enter the first matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println(“Enter the second matrix:”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=sc.nextInt();
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(c[i][j]+“\t”);
}
System.out.println();
}
}
}

50. Write a program to input numbers into a 5×5 integer matrix and check whether it is zero or null matrix or not. A null matrix is a matrix, whose all elements are zero.

Ans.
import java.util.*;
class Sol50
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i][j]!=0)
f=1;
}
}
if(f==0)
System.out.println(“Null Matrix”);
else
System.out.println(“Not a Null Matrix”);
}
}

51. Write a program to input numbers into a 5×5 integer matrix and check whether it is a scalar matrix or not. Scalar matrix is such a matrix whose major diagonal elements are all same.

Ans.
import java.util.*;
class Sol51
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[5][5],i,j,f=0;
System.out.println(“Enter 25 numbers:”);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<5;i++)
{
if(a[i][i]!=a[0][0])
f=1;
}
if(f==0)
System.out.println(“Scalar Matrix”);
else
System.out.println(“Not a Scalar Matrix”);
}
}

52. Create a class named Student containing the following instance variables:
Instance Variables:
roll[ ] of int type array reference.
name[ ] of String type array reference.
Member functions:
i. Parameterized constructor to initialize the data members.
ii. To accept a roll as parameter and search for it in roll[]. If found, the corresponding name should be displayed otherwise a relevant message should be displayed.

Ans.
import java.util.*;
class Student
{
int roll[];
String name[];
Student(int r[],String n[])
{
roll=r;
name=n;
}
void search(int r)
{
int i,f=0;
for(i=0;i<roll.length;i++)
{
if (roll[i]==r)
{
System.out.println(“Name:”+name[i]);
f=1;
}
}
if(f==0)
}
}

53. Create a method which accepts an integer as parameter and return true if it is a prime number, otherwise return false. Now use it in another method which accepts a two-dimensional integer array as parameter and check whether all the elements of the minor diagonal are prime numbers or not.

Ans.
import java.util.*;
class Sol53
{
static boolean isPrime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
static void main(int a[][])
{
int i,j,f=0;
for(i=0;i<a.length;i++)
{
for(j=0;j<a[0].length;j++)
{
if(i+j==a[0].length-1)
{
if(isPrime(a[i][j])==false)
f=1;
}
}
}
if(f==0)
System.out.println(“All no.s of the minor diagonal are prime”);
else
System.out.println(“All no.s of the minor diagonal are not prime”);
}
}

54. Write a program to input and sort the weight of ten people. Sort and display them in descending order using the selection sort technique.

Ans.
import java.util.*;
class Sol54
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10],i,j,s,p;
System.out.println(“Enter 10 numbers:”);
for(i=0;i<10;i++)
a[i]=sc.nextInt();
for(i=0;i<9;i++)
{
s=a[i];p=i;
for(j=i+1;j<10;j++)
{
if(a[j]<s)
{
s=a[j];
p=j;
}
}
a[p]=a[i];
a[i]=s;
}
System.out.println(“Sorted Array:”);
for(i=0;i<10;i++)
{
System.out.print(a[i]+“ ”);
}
}
}

55. The annual examination results of 50 students in a class is tabulated as follows.
Write a program to read the data, calculate and display the following:
a. Average mark obtained by each student.
b. Print the roll number and average marks of the students whose average mark is above 80.
c. Print the roll number and average marks of the students whose average mark is below 40.

Ans.
import java.util.*;
class Sol55
{
static void main()
{
Scanner sc=new Scanner(System.in);
int roll[]=new int[50],i;
int m1[]=new int[50],m2[]=new int[50],m3[]=new int[50];
float av[]=new float[50];
System.out.println(“Enter the roll and marks:”);
for(i=0;i<50;i++)
{
roll[i]=sc.nextInt();
m1[i]=sc.nextInt();
m2[i]=sc.nextInt();
m3[i]=sc.nextInt();
av[i]=(float)(m1[i]+m2[i]+m3[i])/3;
}
System.out.println(“Average marks obtained by each student:”);
System.out.println(“Roll\t\tAverage”);
for(i=0;i<50;i++)
{
System.out.println(roll[i]+“\t\t”+av[i]);
}
System.out.println(“Average marks above 80 obtained by each student:”);
System.out.println(“Roll\t\tAverage”);
for(i=0;i<50;i++)
{
if(av[i]>80)
System.out.println(roll[i]+“\t\t”+av[i]);
}
System.out.println(“Average marks below 40 obtained by each student:”);
System.out.println(“Roll\t\tAverage”);
for(i=0;i<50;i++)
{
if(av[i]<40)
System.out.println(roll[i]+“\t\t”+av[i]);
}
}
}

56. Write a program to store 6 element in an array P, and 4 elements in an array Q and produce a third array R, containing all elements of array P and Q. Display the resultant array.

Ans.
class Sol56
{
static void main()
{
int P[]={4,12,23,34,45,56};
int Q[]={17,15,12,23};
int R[]=new int[10],i,c=0;
for(i=0;i<6;i++)
{
R[c++]=P[i];
}
for(i=0;i<4;i++)
{
R[c++]=Q[i];
}
System.out.println(“Resultant Array:”);
for(i=0;i<10;i++)
{
System.out.print(R[i]+“\t”);
}
}
}

57. Write a program to accept the year of graduation from school as an integer value from the user. Using the Binary Search technique on the sorted array of integers given below, output the message ‘Record exists’ if the value input is located in the array. If not, output the message Record does not exist”.
(1982, 1987, 1993. 1996, 1999, 2003, 2006, 2007, 2009, 2010)

Ans.
import java.util.*;
class Sol57
{
static void main()
{
Scanner sc=new Scanner(System.in);
int a[]={1982,1987,1993,1996, 1999, 2003, 2006, 2007, 2009, 2010},l,u,n,m,f=0;
n=sc.nextInt();
l=0;u=a.length-1;
while(l<=u)
{
m=(l+u)/2;
if(a[m]==n)
{
f=1;
break;
}
else if(a[m]>n)
u=m-1;
else
l=m+1;
}
if(f==1)
System.out.println(“Record exists”);
else
System.out.println(“Record does not exist”);
}
}

58. Write a program to accept name and total marks of N number of students in two single subscript array name[] and totalmarks[].
Calculate and print:
i. The average of the total marks obtained by N number of students.
ii. Deviation of each student’s total marks with the average.
[deviation=total marks of a student – average]

Ans.
import java.util.*;
class Sol58
{
static void main()
{
Scanner sc=new Scanner(System.in);
int N,i,s=0;
System.out.println(“Enter the no. of students:”);
N=sc.nextInt();
String name[]=new String[N];
int totalmarks[]=new int[N];
float avg,dev;
System.out.println(“Enter the name and total marks:”);
for(i=0;i<N;i++)
{
name[i]=sc.nextLine();
totalmarks[i]=sc.nextInt();
s+=totalmarks[i];
}
avg=(float)s/N;
System.out.println(“Average marks obtained by the students:”+avg);
System.out.println(“Deviation of each student’s total marks with the average”);
for(i=0;i<N;i++)
{
dev=totalmarks[i]-avg;
System.out.println(name[i]+“\t\t”+dev);
}
}
}

We believe that every ICSE student can get good marks by solving Arrays Solutions. So, let’s start to learn Arrays Solutions class 10 for your exam.

You can also learn revision note for class 10 computer application prepared by our expert teachers at icseboards.com