ここで説明されているように、条件付き三項演算子を使用して短縮しようとした4つの異なる条件を持つ非常に大きなコードを取得しました。ただし、2 つ以上の条件があるため、正しい構文を管理できません。そのような場合に三項演算子を使用する方法を誰かが説明できますか? 私のコードは以下になります
いいえ、コードを書くように頼んでいるわけではありません。複数の条件での三項演算子の使用についての説明を探しています。
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));
}