-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgorithm2.java
42 lines (32 loc) · 925 Bytes
/
Algorithm2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Algorithm2{
public static void main(String [] args){
long startTime = System.currentTimeMIlls();
int x = 9999996;
int n = 10000000;
int count = 0;
boolean isEven = n%2 == 0;
if(x >= 0)
if(isEven){
for (int i = 0; i < n; i = i + 2) {
count++;
if (i == x) {
System.out.println("We found the values at " + "+count+" try");
break;
}
}
} else {
for (int i = 1; i < n; i = i + 2) {
count++;
if (i == x) {
System.out.println("We found the values at "+count+" + try");
break;
}
}
}
}else {
System.out.println("Oops! we are expecting valid value");
}
long endTime = System.currentTimeMillis();
System.out.println("Total time :: " + (endTime - startTime) + " ms");
}
}