हिंदी

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.

Advertisements
Advertisements

प्रश्न

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 potiition where it is present in the array. Otherwise display message "not found".

संक्षेप में उत्तर
Advertisements

उत्तर

import java.util.*;
class Lsearch
{
     public static void main(String args[])
     {
          int c, n;
      double array[], search;
      Scanner in = new Scanner(System.in);
      System.out.println("Enter  number  of elements");
      n = in.nextInt();
      array= new double[n];
      System.out.println("Enter those " + n  +" elements");
      for (c = 0; c < n; c++)
         array[c] = in.nextDouble();
   System.out.println("Enter value to find");
   search= in. nextDouble ();
   for (c = 0; c < n; c++)
   {
        if (array[c] = search) /* Searching element is present*/
        {
            System.out.println(search + " is present at
            location" + (c + 1) + ".");
            break;
        }
     }
     if (c = n) /* Element to search isn't present */
     System.out.println(search + " isn't present in array.");
     }
}
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Official

संबंधित प्रश्न

Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique. 


Design a class to overload a function series() as follows: 

(a) void series (int x, int n) – To display the sum of the series given below:
x1 + x2 + x3 + ……………. xn terms

(b) void series (int p) – To display the following series:
0, 7, 26, 63 p terms.

(c) void series () – To display the sum of the series given below:

`1/2 + 1/3 + 1/4 .....1/10`


Name the following :
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.


Differentiate between searching and sorting.


If int x [ ] = { 4, 3,7, 8, 9,10}; what are the values of p and q ?

(i) p = x.length
(ii) q = x[2] + x[5] * x[1]


Write a program to input forty words in an array. Arrange these words in descending order of alphabets, using selection sort technique. Print the sorted array.


Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a = new int (5);
for (int i = 0; i < = 5; i++) a [i] = i;


Consider the given array and answer the question given below:

int x[ ] {4; 7,9,66,72,0,16);

What is the length of the array?


Consider the given array and answer the question given below:

int x[ ] {4; 7,9,66,72,0,16);

What is the value in x[4]?


Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found” using Binary search technique.

5.6, 11.5, 20.8, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.


Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×