Added Ternary Search

This commit is contained in:
Ribhav Pahuja
2017-10-05 00:55:27 +05:30
parent 6807e7e3ea
commit 76042f4713

View File

@ -57,7 +57,7 @@ public class TernarySearch{
System.out.println("Enter number of elements in the array"); System.out.println("Enter number of elements in the array");
int n = s.nextInt(); int n = s.nextInt();
int arr[] = new int[n]; int arr[] = new int[n];
System.out.println("Enter the elements of the array"); System.out.println("Enter the elements of the Sorted array");
for (int i= 0; i < n; i++){ for (int i= 0; i < n; i++){
arr[i] = s.nextInt(); arr[i] = s.nextInt();
} }
@ -68,7 +68,7 @@ public class TernarySearch{
System.out.println(" The element is not present in the array."); System.out.println(" The element is not present in the array.");
} }
else { else {
System.out.println("The element is present at the position" + ans); System.out.println("The element is present at the position " + (ans+1));
} }
} }
} }