1 / 9

独習JAVA

独習JAVA. Chapter 3 3.6 バックスラッシュコード 3.7  関係演算子と論理演算子 3.8  三項演算子. 3.6 バックスラッシュコード. plintln() で Java 言語での特殊な文字コード. バックスラッシュコードとしては上の表のものがあり、通常の文字が使えるところならどこでも使える。. バックスラッシュコードの例. class rei3_6{ public static void main(String args[]){ System.out.print( ” ” hello ’ <br> ” );

nitsa
Download Presentation

独習JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 独習JAVA Chapter 3 3.6 バックスラッシュコード 3.7 関係演算子と論理演算子 3.8 三項演算子

  2. 3.6 バックスラッシュコード plintln()でJava言語での特殊な文字コード バックスラッシュコードとしては上の表のものがあり、通常の文字が使えるところならどこでも使える。

  3. バックスラッシュコードの例 class rei3_6{ public static void main(String args[]){ System.out.print(”\”hello\’\n”); System.out.println(”hello”); } } 出力結果 ”hello’ hello

  4. 3.7 関係演算子と論理演算子 論理演算子 論理演算子には上の表のものがあり関係演算子と論理演算子の優先順位は右のようになる。

  5. 関係演算子と論理演算子の例 class rei3_7{ public static void main(String args[]){ int i = 12, h =8; System.out.println(”i=” + i); System.out.println(”h=” + h); System.out.print(”i < h ” + ( i < h )); } } 出力結果 i=12 h=8 i<h false

  6. 3.8 三項演算子 JAVAにはif-then-elseステートメントの短縮形として働く三項演算子があり下記のような形式になる expr1 ? expr2 : expr3 ここではexpr1は任意の論理式となる。expr1が真ならexpr2が評価され、そうでなでればexpr3が評価される。expr2かexpr3のどちらかの値が三項演算子の結果として返される。expr2とexpr3は同じ型でなければならない。

  7. 三項演算子の例 class rei3_8{ public static void main(String args[]){ System.out.println("今の時間を入力してください"); int i = Integer.parseInt(args[0]); String str1 = "午前", str2="午後"; System.out.print("今は"); System.out.print((i < 11) ? str1 : str2); System.out.println("です"); } } >java rei3_8 12 今は午後です

  8. 宿題 コマンドラインから任意の数2つを入力し2番目に入力した数が一番目に入力した数の約数かどうかを判別するプログラムを作成しなさい。

  9. 解答 class Syukudai2{ public static void main(String args[]){ int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]); System.out.println("i ="+ i); System.out.println("j ="+ j); String str1 = "約数です。", str2="約数ではありません。"; System.out.print("jはiの"); System.out.print(((i%j) == 0) ? str1 : str2); } }

More Related