Computer Science, asked by ssanjith, 5 months ago

Write a program to accept 20 different characters in a single dimensional array (SDA). Now, enter the character and search it by using binary search technique, check whether or not the character is present in the list of array elements. If the character is present then display the message search successful otherwise display search and unsuccessful.​

Answers

Answered by Jasleen0599
0

JAVA CODE

import java.util.Scanner;

public class KboatSDAEvenOdd

{

   public static void main(String args[]) {

       

       final int NUM_COUNT = 20;

       Scanner in = new Scanner(System.in);

       int i = 0;

       

       int arr[] = new int[NUM_COUNT];

       int even[] = new int[NUM_COUNT];

       int odd[] = new int[NUM_COUNT];

       

       System.out.println("Enter 20 numbers:");

       for (i = 0; i < NUM_COUNT; i++) {

           arr[i] = in.nextInt();

       }

       

       int eIdx = 0, oIdx = 0;

       for (i = 0; i < NUM_COUNT; i++) {

           if (arr[i] % 2 == 0)

               even[eIdx++] = arr[i];

           else

               odd[oIdx++] = arr[i];

       }

       

       System.out.println("Even Numbers:");

       for (i = 0; i < eIdx; i++) {

           System.out.print(even[i] + " ");

       }

       

       System.out.println("\nOdd Numbers:");

       for (i = 0; i < oIdx; i++) {

           System.out.print(odd[i] + " ");

       }

   }

}

  • In Java, a one-dimensional array is a grouping of comparable sorts of elements kept in close proximity to one another in memory. Because the data is continuously saved, activities like search, remove, insert, etc. are more simpler. One-dimensional or multi-dimensional arrays are both possible. The most basic type of array is a one-dimensional array, in which each element is stored linearly and may be retrieved individually by providing its index value.
  • While 2D arrays contain a grid of values with several rows and columns, 1D arrays only contain one row of items. 1D: 2D: Similar to a 1D array, an ArrayList has an unlimited length and can include any number of elements.

#SPJ1

Similar questions