Slide 4
Slide 4 text
String[] transactions = {
"paid 20",
"received 10",
"paid 5",
"received 15",
"paid 10",
"received 12"
};
1
2
3
4
5
6
7
8
9
var total = Stream.of(transactions).mapToInt(transaction -> {
10
var parts = transaction.split(" ");
11
int amount = Integer.decode(parts[1]);
12
if (Objects.equals(parts[0], "paid")) {
13
amount = -amount;
14
}
15
16
return amount;
17
}).sum();
18
19
if (total >= 0) {
20
System.out.println("Life is good :)");
21
} else {
22
System.out.println("You are broke :(");
23
}
24
var total = Stream.of(transactions).mapToInt(transaction -> {
String[] transactions = {
1
"paid 20",
2
"received 10",
3
"paid 5",
4
"received 15",
5
"paid 10",
6
"received 12"
7
};
8
9
10
var parts = transaction.split(" ");
11
int amount = Integer.decode(parts[1]);
12
if (Objects.equals(parts[0], "paid")) {
13
amount = -amount;
14
}
15
16
return amount;
17
}).sum();
18
19
if (total >= 0) {
20
System.out.println("Life is good :)");
21
} else {
22
System.out.println("You are broke :(");
23
}
24
var parts = transaction.split(" ");
int amount = Integer.decode(parts[1]);
if (Objects.equals(parts[0], "paid")) {
amount = -amount;
}
return amount;
String[] transactions = {
1
"paid 20",
2
"received 10",
3
"paid 5",
4
"received 15",
5
"paid 10",
6
"received 12"
7
};
8
9
var total = Stream.of(transactions).mapToInt(transaction -> {
10
11
12
13
14
15
16
17
}).sum();
18
19
if (total >= 0) {
20
System.out.println("Life is good :)");
21
} else {
22
System.out.println("You are broke :(");
23
}
24
}).sum();
String[] transactions = {
1
"paid 20",
2
"received 10",
3
"paid 5",
4
"received 15",
5
"paid 10",
6
"received 12"
7
};
8
9
var total = Stream.of(transactions).mapToInt(transaction -> {
10
var parts = transaction.split(" ");
11
int amount = Integer.decode(parts[1]);
12
if (Objects.equals(parts[0], "paid")) {
13
amount = -amount;
14
}
15
16
return amount;
17
18
19
if (total >= 0) {
20
System.out.println("Life is good :)");
21
} else {
22
System.out.println("You are broke :(");
23
}
24
if (total >= 0) {
System.out.println("Life is good :)");
} else {
System.out.println("You are broke :(");
}
String[] transactions = {
1
"paid 20",
2
"received 10",
3
"paid 5",
4
"received 15",
5
"paid 10",
6
"received 12"
7
};
8
9
var total = Stream.of(transactions).mapToInt(transaction -> {
10
var parts = transaction.split(" ");
11
int amount = Integer.decode(parts[1]);
12
if (Objects.equals(parts[0], "paid")) {
13
amount = -amount;
14
}
15
16
return amount;
17
}).sum();
18
19
20
21
22
23
24
String[] transactions = {
"paid 20",
"received 10",
"paid 5",
"received 15",
"paid 10",
"received 12"
};
var total = Stream.of(transactions).mapToInt(transaction -> {
var parts = transaction.split(" ");
int amount = Integer.decode(parts[1]);
if (Objects.equals(parts[0], "paid")) {
amount = -amount;
}
return amount;
}).sum();
if (total >= 0) {
System.out.println("Life is good :)");
} else {
System.out.println("You are broke :(");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
loige
replit.com/@lmammino/r-u-broke-java
4