first commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
+1
Submodule D197_Version_Control/d197-version-control added at 287d367486
+1
Submodule D197_Version_Control/d197-version-controlback added at 6d582531fc
Binary file not shown.
@@ -0,0 +1,31 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SequentialSearch
|
||||||
|
*/
|
||||||
|
public class SequentialSearch {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("check the number x: ");
|
||||||
|
int input = sc.nextInt();
|
||||||
|
int[] arr = { 1, 3, 5, 6, 7, 21, 32, 42, 55, 66, 76, 83, 90 };
|
||||||
|
|
||||||
|
int position = 0;
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
while (position < arr.length && !found) {
|
||||||
|
if (arr[position] == input) {
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
position = position + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
System.out.println(input + " found in position " + position);
|
||||||
|
} else {
|
||||||
|
System.out.println(input + " Not found in the array");
|
||||||
|
}
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* SequentialSearchSortedarray
|
||||||
|
*/
|
||||||
|
public class SequentialSearchSortedarray {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int[] sortedArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||||
|
int index = SeqSearch(sortedArray, 53);
|
||||||
|
if (index != -1) {
|
||||||
|
System.out.println("Element found at index " + index);
|
||||||
|
} else {
|
||||||
|
System.out.println("Element not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int SeqSearch(int[] arr, int value) {
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
if (arr[i] == value) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Squareroot
|
||||||
|
*/
|
||||||
|
public class Squareroot {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("enter your guess");
|
||||||
|
double square = sc.nextDouble();
|
||||||
|
|
||||||
|
// initial the difference
|
||||||
|
double epsilon = 1;
|
||||||
|
// initial guess
|
||||||
|
double guess = square / 2.0;
|
||||||
|
|
||||||
|
while (epsilon > 0.001) {
|
||||||
|
double newGuess = (guess + square / guess) / 2.0;
|
||||||
|
epsilon = Math.abs(square - guess * guess);
|
||||||
|
guess = newGuess;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("The sqaure root of " + square + " is " + guess);
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Submodule
+1
Submodule Scripting_and_Programming_Applications_C867/C867Project/c867-scripting-and-programming-applications added at c3bc5e1255
+1
Submodule c867-scripting-and-programming-applications added at c8c6099b8e
Reference in New Issue
Block a user