1.

write a java program to accept and store 10 elements in a single dimensional array and enter the new element and check whether the element is present or not by using selection Sort algorithm​

Answer»

Program

import java.io.*;

import java.util.*;

PUBLIC class Main{

   public static void main(String args[]){

       int arr[] = new int[10];

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter 10 elements into the array");

       for(int i = 0; i < 10; i++){

           arr[i] = sc.nextInt();

       }

       System.out.println("Enter number to check : ");

       int temp = sc.nextInt();

       for( int i = 0 ; i < 10 ; i++ ){

           if( arr[i] == temp ){

               System.out.println("given number FOUND at "+(i+1)+" POSITION");

               break;

           }

       }

   }

}

Output

Enter 10 elements into the array

12

14

56

34

786

345

23

987

5467

3

Enter number to check : 5467

given number found at 9 position



Discussion

No Comment Found