java
1package test; 2 3public class Test3 { 4 5 public static void main(String[] args) { 6 // TODO 自動生成されたメソッド・スタブ 7 8 String a = "a"; 9 String b = "b"; 10 11 String c = a.equals(b) ? "yes" : "no"; 12 13 System.out.println(c); 14 } 15}
java
1package test; 2 3public class Test3 { 4 5 public static void main(String[] args) { 6 // TODO 自動生成されたメソッド・スタブ 7 8 String a = "a"; 9 String b = "b"; 10 11 String c; 12 if (a.equals(b)){ 13 c = "yes"; 14 }else{ 15 c = "no"; 16 } 17 System.out.println(c); 18 } 19} 20
上記の2つのコードは結果は同じですが、可読性やコード短縮以外に違いはあるのでしょうか?
三項演算子の使用方法についてもいい方法があれば教えていただきたいです。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。