-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerformOperation.java
49 lines (36 loc) · 1.04 KB
/
PerformOperation.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
43
44
45
46
47
48
49
package abc;
import java.util.Scanner;
public class PerformOperation {
public static void main(String[] args) {
PerformOperation pb =new PerformOperation();
Scanner sc = new Scanner(System.in);
System.out.println("Enter number of string to enter: ");
int input =sc.nextInt();
System.out.println("Enter String: ");
String []str = new String[input];
for(int i=0; i<str.length; i++) {
str[i] =sc.next();
}
int res = pb.finalValueAfterOperations(str);
System.out.println(res);
}
public int finalValueAfterOperations(String[] operations) {
int num = 0;
for(int i=0; i<operations.length; i++) {
String []s = operations[i].split("");
if(s[0].equals("-") && s[2].equals("X")) {
num = num-1;
}
else if(s[0].equals("+") && s[2].equals("X")) {
num = num+1;
}
else if(s[1].equals("-") && s[0].equals("X")) {
num = num-1;
}
else if(s[1].equals("+") && s[0].equals("X")){
num = num+1;
}
}
return num;
}
}