| 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» Programimport 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; } } } } OutputEnter 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 |
|