Class 10 ICSE - Java Array Board Questions


Class 10th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 10th java topics includes revision of class 9th, constructors, user-defined methods, objects and classes, library classes , etc.
Program 1:
Solution:
import java.util.*;
class selection
{
    public static void main(String args[])
    {
        int arr[];
        arr=new int[10];
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 10 numbers");
        for(int i=0;i< 10;i++)
        {
            arr[i]=sc.nextInt();
        }
        System.out.println("Original array:");
        for(int i=0;i< 10;i++)
        {
            System.out.print(arr[i]+" ");
        }
        for(int i=0;i< 10;i++) 
        {
            int index = i;
            for(int j= i+1;j< 10;j++) 
            {
                if(arr[j]< arr[index])
                {
                index = j; 
                }  
            } 
            int temp = arr[i];  
            arr[i] = arr[index];  
            arr[index] = temp;
        }
        System.out.println("Sorted array:");
        for(int i=0;i< 10;i++)
        {
            System.out.print(arr[i]+" ");
        }
    }
}
                        

Program 2: Define a class to accept values into an array of double data type of size 20. Accept a double value from user and search in the array using linear search method. If value is found , display message “Found” with its position where it is present in the array. Otherwise display message “not found”.
Solution:
import java.util.*; 
class LinearSearch 
{ 
    public static void main(String args[]) 
    {
        double a[] = new double[20]; 
        Scanner sc = new Scanner(System.in); 
        System.out.println("Enter 20 values in Array"); 
        for(int i=0; i< 20; i++) 
        { 
            a[i] = sc.nextDouble(); 
        } 
        System.out.println("Enter the value to be searched?"); 
        double x = sc.nextDouble(); 
        int pos = -1; 
        for(int i=0; i< a.length; i++) 
        { 
            if(a[i] == x) 
            { 
              pos = i; 
              break; 
            } 
        } 
        if(pos != -1) 
            System.out.println("Element is found at "+(pos+1)); 
        else 
            System.out.println("Element is not found.");   
    }
}
                        

Program 3: Write a program to input 5 elements in an array and display them and print how many even and odd elements are present in the array.
Solution:
import java.util.*;
class evenodd
{
    public static void main(String args[])
    {
        int arr[]=new int[5];
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 5 numbers");
        for(int i=0;i< ;i++)
        {
            arr[i]=sc.nextInt();
        }
        int e=0,o=0;
        for(int i=0;i< 5;i++) 
        {
            if(arr[i]%2==0)
            e++;
            else
            o++;
        }
        System.out.println("Displaying array:");
        for(int i=0;i< 5;i++)
        {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        System.out.println("No of even elements=" +e);
        System.out.println("No of odd elements=" +o);

    }
}
                        

Program 4: Write a program to input 5 elements in an array and display them and perform following operations:
- Product of all elements and print it.
- Square of each element and print it.
Solution:
import java.util.*;
class squareprod
{
    public static void main(String args[])
    {
        int arr[]=new int[5];
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 5 numbers");
        for(int i=0;i< 5;i++)
        {
            arr[i]=sc.nextInt();
        }
        System.out.println("Displaying array:");
        for(int i=0;i< 5;i++)
        {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        int prod =1;
        for(int i=0;i< 5;i++) 
        {
            int sq=1;
            prod = prod*arr[i];
            sq = arr[i]*arr[i];
            System.out.println("Square of element "+(i+1)+ " =" +sq);
        }
        System.out.println("Product of all elements=" +prod);
    }
}
                        

Program 5: Write a program to input 5 elements in an array and display them and perform following operations:
- Sum of all elements and print it.
- Largest element and print it.
Solution:
import java.util.*;
class arrayprog
{
    public static void main(String args[])
    {
        int arr[]=new int[5];
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 5 numbers");
        for(int i=0;i< 5;i++)
        {
            arr[i]=sc.nextInt();
        }
        System.out.println("Displaying array:");
        for(int i=0;i< 5;i++)
        {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        int sum =0,max=arr[0];
        for(int i=0;i< 5;i++) 
        {
            sum = sum+arr[i];
            if(arr[i]>max)
            max=arr[i];
        }
        System.out.println("Largest element=" +max);
        System.out.println("Sum of all elements=" +sum);
    }
}
                        

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com