我得到了一个包含 4 个不同条件的相当大的代码,我尝试使用这里描述的条件三元运算符来缩短这些代码。但是,我无法管理正确的语法,因为我有两个以上的条件。有人可以解释在这种情况下如何使用三元运算符吗?我的代码在下面
不,我不是要为我编写代码,我正在寻找有关在多个条件下使用三元运算符的解释
if (mp.getCurrentPosition() / 1000 / 60 < 10
&& mp.getCurrentPosition() / 1000 % 60 < 10) {
tvTimeElapsed.setText("0"
+ Integer.toString(mp.getCurrentPosition() / 1000 / 60)
+ ":" + "0"
+ Integer.toString(mp.getCurrentPosition() / 1000 % 60));
} else if (mp.getCurrentPosition() / 1000 / 60 < 10
&& mp.getCurrentPosition() / 1000 % 60 >= 10) {
tvTimeElapsed.setText("0"
+ Integer.toString(mp.getCurrentPosition() / 1000 / 60)
+ ":"
+ Integer.toString(mp.getCurrentPosition() / 1000 % 60));
} else if (mp.getCurrentPosition() / 1000 / 60 >= 10
&& mp.getCurrentPosition() / 1000 % 60 < 10) {
tvTimeElapsed
.setText(Integer.toString(mp.getCurrentPosition() / 1000 / 60)
+ ":"
+ "0"
+ Integer.toString(mp.getCurrentPosition() / 1000 % 60));
} else {
tvTimeElapsed
.setText(Integer.toString(mp.getCurrentPosition() / 1000 / 60)
+ ":"
+ Integer.toString(mp.getCurrentPosition() / 1000 % 60));
}