-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuadrOvertakeLinear.java
More file actions
58 lines (50 loc) · 1.36 KB
/
QuadrOvertakeLinear.java
File metadata and controls
58 lines (50 loc) · 1.36 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @author marios yiannakou
*
* Given a number, a linear starting point and a quadratic starting point,
* calculate how many iterations it takes for the quadratic number
* to become larger than the linear number.
*
* Exit Codes:
* -1 - Erroneous input
* -2 - Wrong number of arguments
*/
public class QuadrOvertakeLinear {
public static void main(String[] args) {
if (args.length != 3) {
System.err.println("Please provide exactly 3 arguments");
System.exit(-2);
}
int num = 0;
int LINEAR = 0;
int QUADRATIC = 0;
try {
num = Integer.parseInt(args[0]);
LINEAR = Integer.parseInt(args[1]);
QUADRATIC = Integer.parseInt(args[2]);
} catch (Exception e) {
System.err.println("FATAL ERROR: " + e.getMessage());
System.exit(-1);
}
int q = 0;
int l = 0;
int counter = 0;
while(true) {
l = LINEAR * num;
q = (QUADRATIC * QUADRATIC) * num;
if (q == l) {
System.out.println("Equal.");
break;
} else if (q > l) {
System.out.print("Quadratic surpassed linear after ");
break;
}
QUADRATIC ++;
LINEAR ++;
counter ++;
}
System.out.println(counter + " iterations.");
System.out.println("Linear value: " + l);
System.out.println("Quadratic value: " + q);
}
}