-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBit.java
More file actions
23 lines (18 loc) · 684 Bytes
/
Copy pathBit.java
File metadata and controls
23 lines (18 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
public class Bit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // Scanner to read input
int n = sc.nextInt(); // Number of operations
int x = 0; // Initialize x to 0
while (n-- > 0) { // Loop n times
String s = sc.next(); // Read each operation as a string
if (s.charAt(1) == '+') { // Check if the second character is '+'
++x; // Increment x
} else {
--x; // Decrement x
}
}
System.out.println(x); // Output the final value of x
sc.close(); // Close the scanner
}
}