解きながら学ぶJava入門編

Similar documents
新・明解Java入門

Java演習(4) -- 変数と型 --

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

明解Javaによるアルゴリズムとデータ構造

新・明解Javaで学ぶアルゴリズムとデータ構造

JavaプログラミングⅠ

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

JavaプログラミングⅠ

K227 Java 2

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 今日の講義講義で学ぶ内容 switch 文 論理演算子 条件演算子 条件判断文 3 switch 文 switch 文 式が case のラベルと一致する場所から直後の break; まで処理しますどれにも一致致しない場合 def

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

1: JX-model XML File Package Import Class Intf Ctor Method SInit Field Param Local ExtdOpt ImplOpt ThrwOpt Members QName Type Stmt Label Expr ident li

Java学習教材

情報技術 Java の特徴 Java は現在 事務処理計算用プログラミング言語として開発された COBOL に取って代わり C 言語や C++ と並んで 現在最も使われているプログラミング言語の一つである Java は Write Once, Run Anywhere( プログラムを一度作成したらど

3,, となって欲しいのだが 実際の出力結果を確認すると両方の配列とも 10, 2, 3,, となってしまっている この結果は代入後の配列 a と b は同じものになっていることを示している つまり 代入演算子 = によるの代入は全要素のコピーではなく 先をコピーする ため 代入後の a と b は

r1.dvi


新・明解Javaで学ぶアルゴリズムとデータ構造

Javaによるアルゴリズムとデータ構造

明解Java入門編

untitled

8 if switch for while do while 2

Java updated

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

解きながら学ぶC++入門編

break 文 switch ブロック内の実行中の処理を強制的に終了し ブロックから抜けます switch(i) 強制終了 ソースコード例ソースファイル名 :Sample7_1.java // 入力値の判定 import java.io.*; class Sample7_1 public stati

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

明解Javaによるアルゴリズムとデータ構造

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 条件判断文 3 switch 文 switch 文式が case の値と一致した場合 そこから直後の break; までを処理し どれにも一致しない場合 default; から直後の break; までを処理する 但し 式や値 1

スライド 1

Java講座

‚æ4›ñ

Quick Sort 計算機アルゴリズム特論 :2017 年度 只木進一

コーディング基準.PDF

ALG ppt

Thread

untitled

Make the Future Java FY13 PPT Template

2

問題1 以下に示すプログラムは、次の処理をするプログラムである

目的 泡立ち法を例に Comparableインターフェイスの実装 抽象クラスの利用 型パラメタの利用 比較 入替 の回数を計測

アルゴリズムとデータ構造1

プログラミング入門1

第 1 章 Java 言語について ( オブジェクト指向, 変数の扱い方, 繰り返し条件と条件分岐 ) Java 言語の概要とオブジェクト指向, 変数の扱い方, 繰り返し条件と条件分岐について理解し, プログラム作成を行う 1.1 Java 言語の概要 JAVA は Sun Microsystems

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

untitled

新・明解C言語で学ぶアルゴリズムとデータ構造

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

2

I java A

Microsoft PowerPoint ppt

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

Java プログラミング Ⅰ 3 回目変数 変数 変 数 一時的に値を記憶させておく機能型 ( データ型 ) と識別子をもつ 2 型 ( データ型 ) 変数の種類型に応じて記憶できる値の種類や範囲が決まる 型 値の種類 値の範囲 boolean 真偽値 true / false char 2バイト文

Javaハンドブック

ALG2012-C.ppt

226

Microsoft Word - NonGenList.doc

VB.NETコーディング標準

System.out.println("char : " + (int)character.min_value + "~" + (int)character.max_value); System.out.println("float : " + Float.MIN_VALUE + "~" + Flo

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

r02.dvi


ohp02.dvi

r3.dvi

新・明解Java入門

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

Microsoft Word - NonGenTree.doc

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

2.2 Java C main Java main 2 C 6 C Java 3 C Java ( ) G101Hello.java G101Hello main G101Hello.java /* G101Hello */ class G101Hello { /* main */ public s

Microsoft Word - keisankigairon.ch doc

untitled

2

新版明解C言語 実践編

教材ドットコムオリジナル教材 0から始めるiアフ リ リファレンス i アプリ簡易リファレンス ver i アプリ Java 独自のメソッド (1)iアプリの命令を使えるようにする import com.nttdocomo.ui.*; (2) 乱数を使う import java.u

class TestPrimitiveType{ public static

プログラミング入門1

Microsoft Word - java a.doc

** 平成 16 年度 FE 午後問題 Java** 示現塾プロジェクトマネージャ テクニカルエンジニア ( ネットワーク ) など各種セミナーを開催中!! 開催日 受講料 カリキュラム等 詳しくは 今すぐアクセス!! 平成 16

JEB Plugin 開発チュートリアル 第4回

ex01.dvi

問題1 以下に示すプログラムは、次の処理をするプログラムである

2016 年度 JAVA 講座第六週目 目次 パッケージ... 2 パッケージの作成... 2 パッケージの使用方法... 3 異なるパッケージ同名クラスの宣言... 4 パッケージの側面から見たアクセス修飾子... 4 ラッパークラス... 5 ラッパークラス利用法:キャスト... 5 ラッパーク

解答上の注意 1 解答は 解答 紙の問題番号に対応した解答欄にマークしなさい 2 選択肢は 問ごとに 意されています 問 1の選択肢は 問 2で使 しません 3 選択肢は量が多いため 探しやすさの観点よりグループ分けされています グループ分けに合わせて解答欄が区切られていますが 横 1 列で問題 1

ALG2012-F.ppt

プログラミングA

デジタル表現論・第4回

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

A B 1: Ex. MPICH-G2 C.f. NXProxy [Tanaka] 2:

Microsoft PowerPoint - netpro_2015_02.ppt [互換モード]

(Basic Theory of Information Processing) Fortran Fortan Fortan Fortan 1

JAVA 11.4 PrintWriter 11.5

Java (7) Lesson = (1) 1 m 3 /s m 2 5 m 2 4 m 2 1 m 3 m 1 m 0.5 m 3 /ms 0.3 m 3 /ms 0.6 m 3 /ms 1 1 3

アルゴリズムとデータ構造1

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

JAVA とテンプレート

JavaプログラミングⅠ

ALG2012-A.ppt

Transcription:

44 // class Negative { System.out.print(""); int n = stdin.nextint(); if (n < 0) System.out.println(""); -10 Ÿ 35 Ÿ 0 n if statement if ( ) if i f ( ) if n < 0 < true false true false boolean literalboolean if Fig.3-1 Fig.3-1

45n 0 true System.out.println(""); n 0 < relational operatortable 3-1 <= >= =< => < = < = Table 3-1 3 x < y x > y x <= y x >= y x y true false x y true false x y true false x y true false if if-then if-then- if Fig.3-2 if if ( ) Fig.3-2 if if ( ) if ( ) if-then if-then- if

46 Java3-1p.59 // class Absolute1 { System.out.print(""); int n = stdin.nextint(); if (n >= 0) System.out.println("" + n + ""); System.out.println("" + (-n) + ""); 62 Ÿ 62-35 Ÿ 35 // class Absolute2 { System.out.print(""); int n = stdin.nextint(); int abs; if (n >= 0) abs = n; abs = -n; System.out.println("" + abs + ""); 0 5-5 5 5 n n 0 n n n -n n 0 Absolute1 if if ( ) if true false Fig.3-3 n 0

47 Fig.3-3 Absolute2 if-then- n abs Absolute1 Absolute2 if-then if-then- 4 4 4 n 0 Fig.3-1 if-then if-then- 3 if (n < 0) System.out.println(""); ; if empty statement Fig.3-4 ; Fig.3-4

48 Java3-3p.59 // class Measure1 { 12 Ÿ 4 Ÿ System.out.print(""); int a = stdin.nextint(); System.out.print(""); int b = stdin.nextint(); if (a % b == 0) System.out.println(""); System.out.println(""); b a a b 0 4 12 12 4 0 5 12 12 5 2 if == ==!= equality operatortable 3-2 true false Table 3-2 x == y x!= y x y true false x y true false!= if if (a % b!= 0) System.out.println(""); System.out.println("");

49! // class Measure2 { System.out.print(""); int a = stdin.nextint(); System.out.print(""); int b = stdin.nextint(); if (!(a % b == 0)) System.out.println(""); System.out.println(""); 12 Ÿ 5 Ÿ 3! logical complement operator false true true false Table 3-3 if a % b 0 a % b == 0 true!(a % b == 0) false a % b 0 a % b == 0 false!(a % b == 0) true Table 3-3!x x false true true false a 1 3 1 <= a <= 3 // && a >= 1 && a <= 3 // a1a3 a b c a == b == c // && a == b && b == c // abbc a == b && a == c // abac

50 JavaList 3-5p.58 // class Sign { System.out.print(""); int n = stdin.nextint(); if (n > 0) System.out.println(""); if (n < 0) System.out.println(""); System.out.println(""); 37 Ÿ 0 Ÿ -35 Ÿ 0 if if ( ) if ( ) if if if Fig.3-5 if if System.out. Fig.3-7 if (n > 0) println(""); if (n < 0) println(""); println(""); Fig.3-5

51 Java3-2p.59 if (n == 0) if if (n > 0) System.out.println(""); if (n < 0) System.out.println(""); if (n == 0) System.out.println(""); n > 0 n < 0 false n 0 n n 0 if 3 if (n == 1) System.out.println(""); if (n == 2) System.out.println(""); if (n == 3) System.out.println(""); n 1 2 3 if if ( ) if ( ) if n 4 5-10 1 2 if (n == 1) System.out.println(""); if (n == 2) System.out.println(""); if (n == 3) System.out.println(""); ; if Sign if if ( )

52 Java3-4p.61 a, b a b a b // class Balance { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); if (a > b) System.out.println("a"); if (a < b) System.out.println("b"); System.out.println("ab"); a12 Ÿ b3 Ÿ a a5 Ÿ b15 Ÿ b a b if if Fig.3-6 a b a b Fig.3-6

53// class BalanceWrong { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); int diff = a - b; if (diff > 0) System.out.println("a"); if (diff < 0) System.out.println("b"); System.out.println("ab"); a2147483647 Ÿ b-1 Ÿ b a-2147483648 Ÿ b1 Ÿ a 3 BalanceWrong a b diff 0 a b 2147483647-1 1-2147483648 int -2147483648 +2147483647 2147483647-1 -2147483648 1 int

54 Java3-5p.61 // class GoInto5 { System.out.print(""); int n = stdin.nextint(); if (n > 0) if (n % 5 == 0) System.out.println(""); System.out.println(""); System.out.println(""); 35 Ÿ 36 Ÿ 5 if Fig.3-7 if if if if Fig.3-8 Fig.3-6 4 if (n > 0) if (n % 5 == 0) println(""); println(""); println(""); Fig.3-7

55 Fig.3-8 3 expression abc + 32 abc 32 + abc + 32 xyz = abc + 32 xyz, abc, 32, abc + 32, xyz = abc + 32 4 4 xyz abc + 32 xyz = abc + 32 4 4 assignment expression ; a = c + 32 4 4 Fig.3-9 expression statement ; Fig.3-9

56 Java3-6p.61 10 10 10 // class MultipleOf10 { System.out.print(""); int n = stdin.nextint(); 1250 Ÿ 10 1254 Ÿ 10 if (n > 0) if (n % 10 == 0) System.out.println("10"); System.out.println("10"); System.out.println(""); 10 10 evaluation Fig.3-10 int n 1254 n, 10, n % 10 n 1254 1254, 10, 4 int int 1254 int 10 n % 10 int 4 Fig.3-10

57 Java3-7p.61 3 3 3 1 3 2 // class Modulo3 { System.out.print(""); int n = stdin.nextint(); 1251 Ÿ 3 1253 Ÿ 32 if (n > 0) if (n % 3 == 0) System.out.println("3"); if (n % 3 == 1) System.out.println("31"); System.out.println("32"); System.out.println(""); 3 if if if if if n if (n > 0); System.out.println(""); n (n > 0) ; if if (n > 0) ; // ifn > 0 System.out.println(""); // if if ( )

58 Java3-8p.69 0 59 60 69 70 79 80 100 // && class Grade1 { 68 Ÿ System.out.print(""); int point = stdin.nextint(); if (point >= 0 && point <= 59) System.out.println(""); if (point >= 60 && point <= 69) System.out.println(""); if (point >= 70 && point <= 79) System.out.println(""); if (point >= 80 && point <= 100) System.out.println(""); System.out.println(""); 89 Ÿ 102 Ÿ && Fig.3-11 logical and operator x && y x y true true false x ytable 3-4 true point 0 4 4 59 && x y x && y true true true true false false false true false false false false x y x y true true true true false true false true true false false false Fig.3-11

59 System.out.print(""); int point = stdin.nextint(); if (point < 0 point > 100) System.out.println(""); if (point <= 59) System.out.println(""); if (point <= 69) System.out.println(""); if (point <= 79) System.out.println(""); System.out.println(""); 3 // class Grade2 { Grade2 logical or operator x y x y true true false x y 4 4 4 4 l 4 4 4 point 0 100 true point 0 100 0 59 point 60 100 60 69 Grade2 Grade1 Table 3-4 x && y x y x y true true false x y true true false

60 Java3-9p.71 // if class Max2A { System.out.print("a"); double a = stdin.nextdouble(); System.out.print("b"); double b = stdin.nextdouble(); double max; // if (a > b) max = a; max = b; System.out.println("" + max + ""); a25.7 Ÿ b15.3 Ÿ 25.7 a, b a b max a max b if max Max2B if? : Table 3-5 conditional operator conditional expression Fig.3-12 max a b a b if a > b? a : b a > b? a : b double 25.7 double 3.14 Fig.3-12

61// class Max2B { System.out.print("a"); double a = stdin.nextdouble(); System.out.print("b"); double b = stdin.nextdouble(); double max = a > b? a : b; // System.out.println("" + max + ""); Table 3-5 x? y : z x true y z 3 x true z false y println max System.out.println("" + (a > b? a : b) + ""); ( ) Grade1 point -10 if point >= 0 && point <= 59 point >= 0 false point <= 59 false && false 4 4 4 4 4 Grade2 point < 0 point > 100 point -10 point < 0 true point > 100 true true 4 4 4 4 4 short circuit evaluation && & & & &

62 Java3-10p.71 // if class Diff2A { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); int diff; if (a >= b) diff = a - b; diff = b - a; System.out.println("" + diff + ""); a12 Ÿ b3 Ÿ 9 a3 Ÿ b12 Ÿ 9 // class Diff2B { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); int diff = a >= b? a - b : b - a; System.out.println("" + diff + ""); 0 Diff2A if Diff2B println diff System.out.println("" + (a >= b? a - b : b - a) + "");

63 Java3-11p.71 10 10 11 // 10 class Diff2digits1 { System.out.print(""); int a = stdin.nextint(); System.out.print(""); int b = stdin.nextint(); int diff = a >= b? a - b : b - a; if (diff <= 10) System.out.println("10"); System.out.println("11"); 12 Ÿ 3 Ÿ 10 35 Ÿ 23 Ÿ 11 3 // 10 class Diff2digits2 { System.out.print(""); int a = stdin.nextint(); System.out.print(""); int b = stdin.nextint(); int diff = a >= b? a - b : b - a; System.out.println("" + (diff <= 10? "10" : "11") + ""); a b Diff2B Diff2digits1 if Diff2digits2 Diff2digits2 "" ""

64 Java3-12p.73 // class Min3 { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); System.out.print("c"); int c = stdin.nextint(); int min = a; if (b < min) min = b; if (c < min) min = c; System.out.println("" + min + ""); a3 Ÿ b1 Ÿ c2 Ÿ 1 a, b, c min a b min min b c min min c algorithm Fig.3-13 Fig.3-13

65 a, b, c 3, 1, 2 Fig.3-14 min a, b, c 1, 2, 3 3, 2, 1 5, 5, 5 3, 1, 3 int min = a; if (b < min) min = b; a = 3 b = 1 c = 2 min 3 1 a = 1 b = 2 c = 3 min 1 1 a = 3 b = 2 c = 1 min 3 2 a = 5 b = 5 c = 5 min 5 5 a = 3 b = 1 c = 3 min 3 1 3 if (c < min) min = c; 1 1 1 5 1 Fig.3-14

66 Java3-13p.73 1, 2, 3 2 3, 2, 3 3 4, 4, 4 4 // class Med3 { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); System.out.print("c"); int c = stdin.nextint(); int med; if (a >= b) if (b >= c) med = b; if (a <= c) med = a; med = c; if (a > c) med = a; if (b > c) med = c; med = b; a152 Ÿ b324 Ÿ c75 Ÿ 152 System.out.println("" + med + ""); Fig.3-15 a, b, c median Med3 med,,, Fig.3-15 if ((b >= a && c <= a) (b <= a && c >= a)) med = a; if ((a > b && c < b) (a < b && c > b)) med = b; med = c;

67 3 Fig.3-15 Fig.3-16 Fig.3-16

68 Java3-14p.77 // class MinMaxEq { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); if (a == b) System.out.println(""); { a12 Ÿ b3 Ÿ 3 12 int min, max; // if (a < b) { // ab min = a; max = b; a17 Ÿ { b17 Ÿ min = b; max = a; System.out.println("" + min + ""); System.out.println("" + max + ""); a == b Fig.3-17 if (a == b) System.out.println(""); { int min, max; if (a < b) { min = a; max = b; { min = b; max = a; System.out.println("" + min + ""); System.out.println("" + max + ""); if () { if Fig.3-17

69{ if { block Fig.3-18 { Fig.3-18 3 if if ( ) if ( ) 4 4 4 4 4 4 4 4 4 4 4 4 if if min max if if a b { min = a; max = b; { min = b; max = a; if { if if if if (a < b) min = a; max = b; min = b; max = a; if ( ) ;

70 Java3-15p.77 // class Sort2Descending { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); if (a < b) { // ab int t = a; a = b; b = t; // System.out.println("ab"); System.out.println("a" + a + ""); System.out.println("b" + b + ""); a13 Ÿ b57 Ÿ ab a57 b13 a, b a b sort a b a b a b t a t b a t a b a b a 13 b 57 Fig.3-19 a 57 b 13

71 a a 13 b t b 57 Fig.3-19 t - 13 57 13 57 57 13 t = a; a = b; b = t; if if 1 2 57 13 13 if (a == 1) if (b == 1) 1 2 if if if if (a == 1) if (b == 1) 3 1 a 1 b 1 1 a 1 b 1 2 a 1 2 a 1 b 1 if a 1 if (a == 1) if (b == 1) 1 2 if (a == 1) { if (b == 1) 1 2

72 Java3-16p.77 // class Sort3 { System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); System.out.print("c"); int c = stdin.nextint(); if (a > b) { // abab int t = a; a = b; b = t; if (b > c) { // bcbc int t = b; b = c; c = t; if (a > b) { // abab int t = a; a = b; b = t; System.out.println("abc"); System.out.println("a" + a + ""); System.out.println("b" + b + ""); System.out.println("c" + c + ""); a53 Ÿ b35 Ÿ c42 Ÿ abc a35 b42 c53 a, b, c if Fig.3-20 a, b, c 5, 3, 2 if t t a b a b if b c b c c if c c a, b b if

73if (a > b) ab if (b > c) bc if (a > b) ab Fig.3-20 a b c 5 3 2 3 5 2 3 2 5 2 3 5 a b b 5 3 2 a b c c b a Fig.3-21 a, b, c 5, 3, 4 a > b 3 if (a > b) ab if (b > c) bc if (a > b) ab a b c 5 3 4 3 5 4 3 4 5 3 4 5 5 3 4 a b c Fig.3-21

74 Java3-17p.83 0, 1, 2 0 "" 1 "" 2 "" // import java.util.random; class FingerFlashing { Random rand = new Random(); System.out.print(""); int hand = rand.nextint(3); // 02 switch (hand) { case 0: System.out.println(""); break; case 1: System.out.println(""); break; case 2: System.out.println(""); break; 0 ""1 ""2 "" switch statement switch switch ( ) switch hand 1 case 1: case 1 label hand 1 Fig.3-22 System.out.println(""); break statement break; switch

75 switch ( hand ) { case 0: System.out.println(""); break; case 1: System.out.println(""); break; case 2: System.out.println(""); break; Fig.3-22 break switch hand 1 "" "" hand 0 "" 2 "" break switch switch hand 0, 1, 2 switch 3 case 2 "" break break switch break 3 switch switch (hand) { case 0: System.out.println(""); break; case 1: System.out.println(""); break; case 2: System.out.println(""); break; case 3: System.out.println(""); break; switch case 2: break case 2: break break break

76 Java3-18p.83 1 12 // class Season { System.out.print(""); int month = stdin.nextint(); 6 Ÿ 11 Ÿ switch (month) { case 3 : case 4 : case 5 : System.out.println(""); break; case 6 : case 7 : case 8 : System.out.println(""); break; case 9 : case 10 : case 11 : System.out.println(""); break; case 12 : case 1 : case 2 : System.out.println(""); break; default : System.out.println(""); break; 13 Ÿ switch default: case default break month 3 4 5 switch switch if switch selection statement Fig.3-23 switch ( ) char, byte, short, int, Character, Byte, Short, Integer,

77{ case : default Fig.3-23 break Fig.3-24 break 3 switch switch ( ) break break ; Fig.3-24 if switch switch Fig.3-25 if if a 4 if b 4 c 80 a 1, 2, 3 b 4 if if (a == 4) if (a == 4) switch if (a == 1) c = 10; if (a == 2) c = 20; if (a == 3) c = 50; if (b == 4) c = 80; // ifswitch switch (a) { case 1 : c = 10; break; case 2 : c = 20; break; case 3 : c = 50; break; default : if (b == 4) c = 80; break; Fig.3-25

78 if keyword Table 3-6 Table 3-6 abstract assert boolean break byte case catch char class const continue default do double enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch syncronized this throw throws transient try void volatile while const goto truefalsenull separator Table 3-7 Table 3-7 [ ] ( ) {, :. identifier $ _ $ _ true false null $

79 v v1 va $x $1 _1 If X1000 1 9801 1$!! if #911 -x {x #if 0-1-2 operator Table 3-8 precedence * / + - a + b * c (a + b) * c a + (b * c) + * + ( ) // *+( ) System.out.println("ab" + a * b + ""); //?:+( ) System.out.println("" + (a > b? a : b) + ""); 3 + ( ) ( ) associativity a b c (a b) c a (b c) - 5-3 - 1 (5-3) - 1 // - 5 - (3-1)

80 Table 3-8 [ ] x[y] ( ) x(arg opt ). x.y ++ x++ -- x-- ++ ++x -- --x + +x + - -x -!!x ~ ~x new new new ( ) ( ) * x * y / x / y % x % y + x + y - x - y << x << y >> x >> y >>> x >>> y < x < y > x > y <= x <= y >= x >= y instanceof x instanceof y instanceof == x == y!= x!= y & x & y ^ x ^ y x y && x && y

81 /= x /= y %= x %= y += x += y -= x -= y <<= x <<= y >>= x >>= y >>>= x >>>= y 3 x y? : x? y : z = x = y *= x *= y &= x &= y ^= x ^= y = x = y x int x = 2 x int 2 a b int Fig.3-26 a = b = 1 a = (b = 1) // = b = 1 b 1 b = 1 b int 1 a a b 1 int 1 int 1 Fig.3-26 a = b = 1

82 (1) (1) (2) (3) { (4) a + b * c * (5) + (5) (6) <, >, <=, >= (7) ==,!= (8) &&, (9)! (10)? : (11) (12) if (13) (14) (15) (16) (17) int a = 1, b = 3, c = 5; System.out.println("a < b : " + (a < b)); System.out.println("a <= b : " + (a <= b)); System.out.println("b > c : " + (b > c)); System.out.println("b >= c : " + (b >= c)); System.out.println("a == b : " + (a == b)); System.out.println("a!= b : " + (a!= b)); System.out.println("a - b - c : " + (a - b - c)); System.out.println("c - b - a : " + (c - b - a)); System.out.println("a = b = c : " + (a = b = c)); System.out.println("c = b = a : " + (c = b = a)); a < b : a <= b : b > c : b >= c : a == b : a!= b : a - b - c : c - b - a : a = b = c : c = b = a : (18)

83 x y x && y false false (19) false true (20) true false (21) true true (22) x y x y false false (23) false true (24) true false (25) true true (26) c 0 50 250 c 0 (27) (c (28) 10 == 0) System.out.println("c0"); 3 x 0 (29) (x == 0) System.out.println(""); (30) System.out.println(""); a System.out.println("a" + (31) ); a b System.out.println("ab" + (32) ); System.out.println("ab" + (33) ); w 0 1 2 (34) (w) { (35) 0: System.out.println(""); (36) ; (35) 1: System.out.println(""); (36) ; (35) 2: System.out.println(""); (36) ;

84 (37) (38) + (39) = (40) m 3, 4, 5 if ( (41) (42) (43) ) System.out.println(""); System.out.println(""); if ( (44) && (45) ) System.out.println(""); System.out.println(""); if ( (46) ( (47) (48) )) System.out.println(""); System.out.println(""); m3 if ( (49) ) System.out.println(""); (50) System.out.println(""); (51) System.out.println(""); switch ( (52) ) { case (53) System.out.println(""); break; case (54) System.out.println(""); break; case (55) System.out.println(""); break; a b if ( (56) ) System.out.println("ab"); System.out.println("ab");

85 switch int n 1, 2, 3 (60) (61) (62) int n 0, 1 (63) (64) switch (n) { case 1: System.out.print("A"); case 2: System.out.print("B"); break; default: System.out.print("C"); if (n == 0); System.out.println("A"); 3 a b a b if ( (57) ) { int t = a; a = (58) ; b = (59) ; a b a b if (a * (65) < (66) ) System.out.println("ab"); a, b, c if ( (67) && (68) ) System.out.print(""); a b import (69).util.Scanner; (70) Even { public (71) void main( (72) args) { System.out.print(""); int a = (73).nextInt(); System.out.print(""); int b = (73).nextInt(); int c = 0; if ( (74) ) c = c + 1; if ( (75) ) c = c + 1; if ( (76) == 0) System.out.println(""); if ( (77) ) System.out.println(""); if ( (78) ) System.out.println("");