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

Size: px
Start display at page:

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

Transcription

1 第 1 章 基本的 1 n

2 三値 最大値 algorithm List 1-1 a, b, c max // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); List 1-1 System.out.println(""); 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 max = a; if (b > max) max = b; a, b, c max if (c > max) max = c; System.out.println("" + max + ""); Chap01/Max3.java 実行例 a1 Ÿ b3 Ÿ c2 Ÿ 3 a, b, c max max a b max max b c max max c concatination if ( ) if selection

3 3 Fig.1C-1 import java.util.scanner; a class A { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); b main stdin.nextint() c c 1-1 Column 1-1 数値 文字列 読込 (1) Fig.1C-1 a java.util Scanner Column 2-4p.42 b main csystem.in standard input stream c int stdin.nextint() Column 1-3p.7 Fig.1C-2 int -2,147,483,648 2,147,483,647 System.in stdin stdin stdin List 1-1 a, b, c c a = stdin.nextint(); nextint() stdin a System.in Fig.1C-2

4 41 flowchart Fig.1-1 p.12 max = a; if (b > max) max = b; if (c > max) max = c; a max b > c > a b > max Yes No b max c > max Yes No c max Fig b > max c > max b > max c > max true false if while ( ) if a max a max List 1-1 int max = a; Fig.1-1 max = a;

5 5 a, b, c 1, 3, 2 a, b, c 1, 2, 3 3, 2, 1 5, 5, 5 1, 3, 1 Fig.1-2 max = a; if (b > max) max = b; a a = 1 b = 3 c = 2 max 1 3 b a = 1 b = 2 c = 3 max 1 2 c a = 3 b = 2 c = 1 max 3 3 d a = 5 b = 5 c = 5 max 5 5 e a = 1 b = 3 c = 1 max if (c > max) max = c; Fig.1-2 max a, b, c 6, 10, 7-10, 100, 10 b c a Column 1-2 数値 文字列 読込 (2) Column 1-1 int Table 1C-1 Table 1C-1Scanner next... nextboolean() boolean true false nextbyte() byte nextshort() short nextint() int nextlong() long nextfloat() float E E-45 nextdouble() double E E-324 next() String nextline() String

6 List 1-2 List 1-2 Chap01/Max3m.java // class Max3m { //--- a, b, c ---// static int max3(int a, int b, int c) { int max = a; // if (b > max) max = b; if (c > max) max = c; return max; public static void main(string[] args) { System.out.println("max3(3,2,1) = " + max3(3, 2, 1)); System.out.println("max3(3,2,2) = " + max3(3, 2, 2)); System.out.println("max3(3,1,2) = " + max3(3, 1, 2)); System.out.println("max3(3,2,3) = " + max3(3, 2, 3)); System.out.println("max3(2,1,3) = " + max3(2, 1, 3)); System.out.println("max3(3,3,2) = " + max3(3, 3, 2)); System.out.println("max3(3,3,3) = " + max3(3, 3, 3)); System.out.println("max3(2,2,3) = " + max3(2, 2, 3)); System.out.println("max3(2,3,1) = " + max3(2, 3, 1)); System.out.println("max3(2,3,2) = " + max3(2, 3, 2)); System.out.println("max3(1,3,2) = " + max3(1, 3, 2)); System.out.println("max3(2,3,3) = " + max3(2, 3, 3)); System.out.println("max3(1,2,3) = " + max3(1, 2, 3)); 実行結果 max3(3,2,1) = 3 max3(3,2,2) = 3 max3(3,1,2) = 3 max3(3,2,3) = 3 max3(2,3,2) = 3 max3(1,3,2) = 3 max3(2,3,3) = 3 max3(1,2,3) = 3 // [A] abc // [B] abc // [C] acb // [D] acb // [E] cab // [F] abc // [G] abc // [H] cab // [I bac // [J] bac // [K] bca // [L] bca // [M] cba [A], [B],, [M] Fig.1C-4p.8 A, ʙ,, M method max3 int a, b, c int main max3 Column Column 1-4p.8

7 7 JISJapanese Industrial Standards static int max4(int a, int b, int c, int d) 1-2 static int min3(int a, int b, int c) 1-3 static int min4(int a, int b, int c, int d) p.iv Column 1-3 返却値 呼出 式 評価 return max3 int max 4 4 max(3, 2, 1) Fig.1C-3 max(3, 2, 1) int 3 max(3, 2, 1) int 3 Fig.1C-3

8 81 13 Fig.1C-4 decision tree a b A a b c Yes b c ʙ No a b c C b c a c b a c D a c E a c b c a b a b F a b c b c ɢ b c ʜ a b c a b c a b ɪ b a c a c J b a c K a c b c a b c ʟ b c M b c a c b a Column 1-4 三値 大小関係 中央値 Fig.1C-4 a, b, c List 1-2 A, ʙ,, M 13 List 1C-1 return A, ʙ,, MFig.1C-4

9 9List 1C-1 // import java.util.scanner; class Median { static int med3(int a, int b, int c) { if (a >= b) if (b >= c) return b; A ʙ F ɢ else if (a <= c) return a; D E ʜ else return c; C else if (a > c) return a; ɪ else if (b > c) return c; J K else return b; ʟ M public static void main(string[] args) { Scanner stdin = new Scanner(System.in); Chap01/Median.java 実行例 a1 Ÿ b3 Ÿ c2 Ÿ System.out.println(""); System.out.print("a"); int a = stdin.nextint(); System.out.print("b"); int b = stdin.nextint(); System.out.print("c"); int c = stdin.nextint(); System.out.println("" + med3(a, b, c) + ""); List 1-2 List 1C List 1C-1 med3 static int med3(int a, int b, int c) { if ((b >= a && c <= a) (b <= a && c >= a)) return a; else if ((a > b && c < b) (a < b && c > b)) return b; return c;

10 101 条件判定 分岐 List 1-3 // import java.util.scanner; class JudgeSign { List 1-3 public static void main(string[] args) { Scanner stdin = new Scanner(System.in); System.out.print(""); int n = stdin.nextint(); if (n > 0) System.out.println(""); else if (n < 0) System.out.println(""); else System.out.println(""); ㆒ ㆓ 叅 Chap01/JudgeSign.java 実行例㆒ 5 Ÿ 実行例㆓ -5 Ÿ 実行例叅 0 Ÿ Fig.1-3 n ㆒ ㆓ 0 叅 "Chap01/Judge123A.java" ㆒,, n No Yes n No ㆒㆓ Yes 叅 Fig.1-3 n

11 11if (n == 1) System.out.println(""); else if (n == 2) System.out.println(""); else if (n == 3) System.out.println(""); n 1 ㆒ 2 ㆓ 3 叅 if if () else if () else List 1-3 "Chap01/Judge123B.java" 4 Ÿ n 叅 if "Chap01/Judge123C.java" ㆒ ㆓ 叅 1-1 if (n == 1) System.out.println(""); else if (n == 2) System.out.println(""); else if (n == 3) System.out.println(""); else ; // ㆒ ㆓ 叅 4 4 List 1-3 if Column 1-5 演算子 + - operator operand a > b > a b unary operator a++ binary operator a < b ternary operator a? b : c conditional operator? : Java a? b : c a true b false c ㆒ a = (x > y)? x : y; ㆓ System.out.println((c == 0)? "c" : "c"); ㆒x y a ㆓ c 0 c c

12 121 ( 流 図 ) 記号 flowchart 流 図 (program flowchart) (data) Fig.1-4 処理 (process) Fig.1-5 定義 処理 (predefined process) Fig.1-6 Fig.1-4 Fig.1-5 判断 (decision) Fig.1-7 Fig.1-6 Fig.1-7

13 13 端 (loop limit) Fig.1-8 Fig.1-9 Fig a b i a, b, c i : 1, 1, n i : 1, 1, n Fig.1-9 ab i 1 n 1 n 1, 1, n 1, 2,, n 線 (line) Fig.1-10 Fig.1-10 端子 (terminator) Fig.1-11 Fig.1-11

14 繰返 1 n 整数 和 求 1 n n n n List 1-4Fig.1-12 List 1-4 // 1, 2,, nwhile import java.util.scanner; class SumWhile { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); Chap01/SumWhile.java 実行例 1n n5 Ÿ 1515 System.out.println("1n"); System.out.print("n"); int n = stdin.nextint(); int sum = 0; int i = 1; // ㆒ while (i <= n) { // in sum += i; // sumi i++; // ㆓ i System.out.println("1" + n + "" + sum + ""); while 文 繰返 repetitionloop while 4 while true while ( )

15 15 sum ㆒ ㆓ 1 i i n Yes sum + i sum i + 1 i No i sum i sum Fig n ㆒ ㆓ ㆒ sum 0 i 1 ㆓ i n i n += ++ i n i <= n i sum i sum ㆒ 1 0 i sum i i 5 sum i 5 4 i n while i n n List 1-4 while i n + 1 i

16 161 for 文 繰返 while for 1 n for List 1-5 List 1-5 // 1, 2,, nfor import java.util.scanner; class SumFor { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); System.out.println("1n"); System.out.print("n"); int n = stdin.nextint(); Chap01/SumFor.java 実行例 1n n5 Ÿ 1515 int sum = 0; // for (int i = 1; i <= n; i++) sum += i; // sumi System.out.println("1" + n + "" + sum + ""); Fig.1-13 loop limit i 1, 2, 3, 1 n 1 sum += i; sum i : 1, 1, n sum + i sum i 1 n Fig n

17 17for for (for ; ; for ) for 4 true for List 1-5 n = (1 + 10) * a, b static int sumof(int a, int b) a b a 3 b 5 12 a 6 b 4 15 Column 1-6 for 文 for for for for for for for for for int i; for (i = 1; i <= n; i++) sum += i; // fori for for for (int i = 1; i <= 5; i++) sum += i; for (int i = 1; i <= 7; i++) System.out.println(i);

18 181 正 値 読込 List 1-5 n n List 1-6 List 1-6 Chap01/SumForPos.java // 1, 2,, ndon import java.util.scanner; class SumForPos { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); int n; 実行例 1n n-6 Ÿ n0 Ÿ n10 Ÿ System.out.println("1n"); do { System.out.print("n"); n = stdin.nextint(); while (n <= 0); n int sum = 0; // for (int i = 1; i <= n; i++) sum += i; // sumi System.out.println("1" + n + "" + sum + ""); n 0 n do do while ( ); while for ; do 4 ( ) true Fig.1-14

19 19 Yes n n n n 1-2 a b No n n Fig.1-14 ab ba do n 0 do n 前判定繰返 後判定繰返 相違点 while for false do 1-10 a, b b - a b a b a6 Ÿ b6 Ÿ a b8 Ÿ b - a

20 201 構造化 structured programming Column 1-7 論理演算 法則 p.18list 1-6 List 1C-2 List 1C-2 // 1099 import java.util.scanner; class Digits { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); int no; Chap01/Digits.java 実行例 5 Ÿ 105 Ÿ 57 Ÿ no57 System.out.println(""); do { System.out.print(""); no = stdin.nextint(); while (no < 10 no > 99); System.out.println("no" + no + ""); do List 1-6 no && Fig.1C-5 a b 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.1C-5

21 21 no 5 no < 10 true no > 99 no < 10 no > 99 true x y true x y true true && false false false 4 4 short circuit evaluation 1-2! true false false true!(no >= 10 && no <= 99) 4 4 De Morgan's laws x && y!(!x!y) x y!(!x &&!y) no < 10 no > 99!(no >= 10 && no <= 99) Fig.1C-6 do { /* no */ while (no < 10 no > 99); do { /* no */ while (!(no >= 10 && no <= 99)); ㆒ ㆓ Yes! Yes No No Fig.1C-6

22 221 多重 九九 表 List 1-7 // public class Multi99Table { List 1-7 public static void main(string[] args) { System.out.println(" "); for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) System.out.printf("%3d", i * j); System.out.println(); Chap01/Multi99Table.java 実行結果 Fig.1-15 i j for 4 i for 4 j i j i 1 j * j i 2 j * j i 3 j * j i 9 j * j

23 23 i : 1, 1, 9 i j i j j : 1, 1, 9 i * j Fig ' ' '-' '+' * 5 Ÿ ***** ***** ***** ***** *****

24 241 直角三角形 表示 List 1-8 List 1-8 do n // import java.util.scanner; public class TriangleLB { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); int n; System.out.println(""); Chap01/TriangleLB.java 実行例 5 Ÿ * ** *** **** ***** do { System.out.print(""); n = stdin.nextint(); while (n <= 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) System.out.print('*'); System.out.println(); Fig.1-16 i j n 5 for 4 i 1 n 5 4 for 4 j 1 i 4 i 1 j 1 1 * * i 2 j 1 2 * ** i 3 j 1 3 * *** i 4 j 1 4 * **** i 5 j 1 5 * *****

25 25 i : 1, 1, n i j n 5 i j j : 1, 1, i * Fig n i i '*' n n '*' 1-15 static void trianglelb(int n) // static void trianglelu(int n) // static void triangleru(int n) // static void trianglerb(int n) // 1-16 n 4 static void spira(int n) i (i - 1) * '*' n (n - 1) * '*' * *** ***** ******* 1-17 n static void npira(int n) i i %

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

明解Javaによるアルゴリズムとデータ構造 21 algorithm List 1-1 a, b, c max Scanner Column 1-1 List 1-1 // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); Chap01/Max3.java

More information

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

新・明解C言語で学ぶアルゴリズムとデータ構造 第 1 章 基本的 1 n 141 1-1 三値 最大値 algorithm List 1-1 a, b, c max /* */ #include int main(void) { int a, b, c; int max; /* */ List 1-1 printf("\n"); printf("a"); scanf("%d", &a); printf("b"); scanf("%d",

More information

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

Javaによるアルゴリズムとデータ構造 1 algorithm List 1-1 a, b, c List 1-1 // import java.util.scanner; class Max3 { public static void main(string[] args) { Scanner stdin = new Scanner(System.in); int a, b, c; int max; // Chap01/Max3.java

More information

C言語によるアルゴリズムとデータ構造

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

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

新・明解Javaで学ぶアルゴリズムとデータ構造 第 3 章 探索 Arrays.binarySearch 743 3-1 探索 探索 searching key 配列 探索 Fig.3-1 b c 75 a 6 4 3 2 1 9 8 2 b 64 23 53 65 75 21 3-1 53 c 5 2 1 4 3 7 4 Fig.3-1 a 763 3-2 線形探索 線形探索 linear search sequential search 2

More information

解きながら学ぶJava入門編

解きながら学ぶJava入門編 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

More information

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

明解Javaによるアルゴリズムとデータ構造 74 searching 3 key Fig.3-1 75 2を探索 53を探索 3-1 5 2 1 4 3 7 4 を探索 Fig.3-1 76 3 linear searchsequential search 2 Fig.3-2 0 ❶ ❷ ❸ 配列の要素を先頭から順に走査していく 探索すべき値と等しい要素を発見 Fig.3-2 6 4 3 2 3-2Fig.3-3 77 5 Fig.3-3 0

More information

明解Java入門編

明解Java入門編 1 Fig.1-1 4 Fig.1-1 1-1 1 Table 1-1 Ease of Development 1-1 Table 1-1 Java Development Kit 1 Java List 1-1 List 1-1 Chap01/Hello.java // class Hello { Java System.out.println("Java"); System.out.println("");

More information

K227 Java 2

K227 Java 2 1 K227 Java 2 3 4 5 6 Java 7 class Sample1 { public static void main (String args[]) { System.out.println( Java! ); } } 8 > javac Sample1.java 9 10 > java Sample1 Java 11 12 13 http://java.sun.com/j2se/1.5.0/ja/download.html

More information

Microsoft Word - java a.doc

Microsoft Word - java a.doc 4 入出力の基本として ディスプレイへの文字出力と キーボードからの文字入力の方法を学びます 入出力とは何か 標準出力 標準入力 43 4.1. 入出力とは プログラムと外部機器の間でデータをやりとりすることをいいます プログラムから出て行く方向が 出力 プログラムに入って来る方向が 入力 です 出力 外部機器 プログラム 入力 外部機器 外部機器はさまざまな種類があります 出力を行うには ディスプレイ

More information

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

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println(Hello World); (Basic Theory of Information Processing) Java (eclipse ) Hello World! eclipse Java 1 3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello

More information

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

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

More information

デジタル表現論・第4回

デジタル表現論・第4回 デジタル表現論 第 4 回 劉雪峰 ( リュウシュウフォン ) 2016 年 5 月 2 日 劉 雪峰 ( リュウシュウフォン ) デジタル表現論 第 4 回 2016 年 5 月 2 日 1 / 14 本日の目標 Java プログラミングの基礎 出力の復習 メソッドの定義と使用 劉 雪峰 ( リュウシュウフォン ) デジタル表現論 第 4 回 2016 年 5 月 2 日 2 / 14 出力 Systemoutprint()

More information

新・明解Java入門

新・明解Java入門 第 1 章 画面 文字 表示 Java Java Java Java Java JRE Java JDK 21 1-1 Java Java Java Java 誕生 Fig.1-1 Oak Java Sun Microsystems 2010 Oracle Java Oracle 4 Java http://www.java.com/ http://www.alice.org/ Fig.1-1Java

More information

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

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

More information

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

System.out.println(char :  + (int)character.min_value + ~ + (int)character.max_value); System.out.println(float :  + Float.MIN_VALUE + ~ + Flo 変数と演算子 2 前回は標準出力を行う方法として println print printf について学習した その際 変数についても少し触れたが 今回はより詳しく解説していく また 演算子や標準入力 乱数の生成についても解説する 変数プログラムでデータを取り扱う場合には対象となるデータを保存する必要がでてくる このデータを保存する場所のことを 変数 と呼び 変数を説明する上ではよく データを入れておく箱

More information

スライド 1

スライド 1 第 4 回データの入出力 情報科学部情報メディア学科 鈴木基之 1 前回の演習の答え class CalcMean { public static void main(string[] args){ int a = 10, b = 15; double f; f = ( a + b ) / 2; System.out.println(f); f = ( a + b ) / 2.0; System.out.println(f);

More information

新版 明解C++入門編

新版 明解C++入門編 第 1 章画面 出力 入力 C++ C++ C++ C++ C++ C++ C++ C++ #include using C++ C++ C++ main C++ C++ C++ int double char C++ C++ C++ string C++ C++ C++ 21 1-1 C++ 歴史 C++ C++ 歴史 CC with classes Fig.1-1 C C++ Simula 67

More information

8 if switch for while do while 2

8 if switch for while do while 2 (Basic Theory of Information Processing) ( ) if for while break continue 1 8 if switch for while do while 2 8.1 if (p.52) 8.1.1 if 1 if ( ) 2; 3 1 true 2 3 false 2 3 3 8.1.2 if-else (p.54) if ( ) 1; else

More information

情報処理Ⅰ

情報処理Ⅰ Java フローチャート -1- フローチャート ( 流れ図 ) プログラムの処理手順 ( アルゴリズム ) を図示したもの 記号の種類は下記のとおり 端子記号 ( 開始 終了 ) 処理記号計算, 代入等 条件の判定 条件 No ループ処理 LOOP start Yes データの入力 出力 print など 定義済み処理処理名 end サンプルグログラム ( 大文字 小文字変換 ) 大文字を入力して下さい

More information

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 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 Java Java Java Java 4 p35 4-2 * *** ***** *** * Unix p36 4-3 a,b,c,d 100,200,250,500 a*b = 20000 a*b+c = 20250 a*b+c*d = 145000 (a+b)*(c+d) = 225000 a+b*c+d = 50600 b/a+d/c = 4 p38 4-4 (1) mul = 1

More information

本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(Java) サンプル問題 知識科目 第 1 問 (

本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(Java) サンプル問題 知識科目 第 1 問 ( 本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(Java) サンプル問題 知識科目 第 1 問 ( 知識 4 択 :20 問 ) 1.Java 言語ソースプログラムの拡張子は何か 1 java 2 class

More information

r1.dvi

r1.dvi 2006 1 2006.10.6 ( 2 ( ) 1 2 1.5 3 ( ) Ruby Java Java Java ( Web Web http://lecture.ecc.u-tokyo.ac.jp/~kuno/is06/ / ( / @@@ ( 3 ) @@@ : ( ) @@@ (Q&A) ( ) 1 http://www.sodan.ecc.u-tokyo.ac.jp/cgi-bin/qbbs/view.cgi

More information

Java講座

Java講座 ~ 第 1 回 ~ 情報科学部コンピュータ科学科 2 年竹中優 プログラムを書く上で Hello world 基礎事項 演算子 構文 2 コメントアウト (//, /* */, /** */) をしよう! インデントをしよう! 変数などにはわかりやすい名前をつけよう! 要するに 他人が見て理解しやすいコードを書こうということです 3 1. Eclipse を起動 2. ファイル 新規 javaプロジェクト

More information

新・明解Java入門

新・明解Java入門 537,... 224,... 224,... 32, 35,... 188, 216, 312 -... 38 -... 38 --... 102 --... 103 -=... 111 -classpath... 379 '... 106, 474!... 57, 97!=... 56 "... 14, 476 %... 38 %=... 111 &... 240, 247 &&... 66,

More information

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

3,, となって欲しいのだが 実際の出力結果を確認すると両方の配列とも 10, 2, 3,, となってしまっている この結果は代入後の配列 a と b は同じものになっていることを示している つまり 代入演算子 = によるの代入は全要素のコピーではなく 先をコピーする ため 代入後の a と b は 配列 2 前回には 配列の基本的な使い方と拡張 for 文について学んだ 本日は配列に付いての追加の説明として 配列のコピー 文字列配列 ガーベジコレクション 多次元配列について学んでいく 配列のコピー配列を用意し その全ての要素を別の配列にコピーすることを考える まず 以下に間違った例を示していく プログラム例 1 public class Prog07_01 int[] a = 1, 2, 3,,

More information

JavaプログラミングⅠ

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

More information

Microsoft Word - NonGenTree.doc

Microsoft Word - NonGenTree.doc ジェネリクスとコンパレータを使用しない 2 分探索木のプログラム例 BinTreeNG.java: 2 分探索木のクラス BinTreeNG BinTreeTesterNG.java: BinTreeNG を利用するプログラム例 === BinTreeNG.java =========================================================================

More information

デジタル表現論・第6回

デジタル表現論・第6回 デジタル表現論 第 6 回 劉雪峰 ( リュウシュウフォン ) 2016 年 5 月 16 日 劉 雪峰 ( リュウシュウフォン ) デジタル表現論 第 6 回 2016 年 5 月 16 日 1 / 16 本日の目標 Java プログラミングの基礎配列 ( 復習 関数の値を配列に格納する ) 文字列ファイルの書き込み 劉 雪峰 ( リュウシュウフォン ) デジタル表現論 第 6 回 2016 年

More information

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

解きながら学ぶC++入門編 第 1 章 画面 出力 入力 2 問題 1-1 C++ List 1-1p.4 C++ // cout

More information

Microsoft Word - NonGenList.doc

Microsoft Word - NonGenList.doc ジェネリクスとコンパレータを使用しないリストのプログラム例 1. ポインタによる線形リスト LinkedListNG.java: ポインタによる線形リストのクラス LinkedListNG LinkedListTesterNG.java: LinkedListNG を利用するプログラム例 2. カーソルによる線形リスト AryLinkedListNG.java: カーソルによる線形リストのクラス AryLinkedListNG

More information

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

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 条件判断文 3 switch 文 switch 文式が case の値と一致した場合 そこから直後の break; までを処理し どれにも一致しない場合 default; から直後の break; までを処理する 但し 式や値 1 Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 条件判断文 3 switch 文 switch 文式が case の値と一致した場合 そこから直後の までを処理し どれにも一致しない場合 default; から直後の までを処理する 但し 式や値 1 値 2は整数または文字である switch( 式 ) case 値 1: // コロン : です セミコロン ; と間違えないように!!

More information

r02.dvi

r02.dvi 172 2017.7.16 1 1.1? X A B A X B ( )? IBMPL/I FACOM PL1 ( ) X ( ) 1.2 1 2-0 ( ) ( ) ( ) (12) ( ) (112) (131) 281 26 1 (syntax) (semantics) ( ) 2 2.1 BNF BNF(Backus Normal Form) Joun Backus (grammer) English

More information

ohp02.dvi

ohp02.dvi 172 2017.7.16 1 ? X A B A X B ( )? IBMPL/I FACOM PL1 ( ) X 2 ( ) 3 2-0 ( ) ( ) ( ) (12) ( ) (112) 31) 281 26 1 4 (syntax) (semantics) ( ) 5 BNF BNF(Backus Normal Form) Joun Backus (grammer) English grammer

More information

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

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1 Java (9) 1 Lesson 7 2008-05-20 Java System.out.println() 1 Java API 1 Java Java 1 GUI 2 Java 3 1.1 5 3 1.0 10.0, 1.0, 0.5 5.0, 3.0, 0.3 4.0, 1.0, 0.6 1 2 4 3, ( 2 3 2 1.2 Java (stream) 4 1 a 5 (End of

More information

2

2 問題 1 次の設問 1~5 に答えよ 設問 1. Java のソースプログラムをコンパイルするコマンドはどれか a) java b) javac c) javadoc d) jdb 設問 2. Java のバイトコード ( コンパイル結果 ) を実行するコマンドはどれか a) java b) javac c) javadoc d) jdb 設問 3. Java のソースプログラムの拡張子はどれか a).c

More information

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

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

More information

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

break 文 switch ブロック内の実行中の処理を強制的に終了し ブロックから抜けます switch(i) 強制終了 ソースコード例ソースファイル名 :Sample7_1.java // 入力値の判定 import java.io.*; class Sample7_1 public stati Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 今日の講義で学ぶ内容 switch 文 論理演算子 条件演算子 条件判断文 3 switch 文 switch 文 式が case のラベルと一致する場所から直後の まで処理しますどれにも一致しない場合 default: から直後の まで処理します 式は byte, short, int, char 型 ( 文字または整数 ) を演算結果としますラベルには整数リテラル

More information

Microsoft Word - keisankigairon.ch doc

Microsoft Word - keisankigairon.ch doc 1000000100001010 1000001000001011 0100001100010010 1010001100001100 load %r1,10 load %r2,11 add %r3,%r1,%r2 store %r3,12 k = i + j ; = > (* 1 2 3 4 5 6 7 8 9 10) 3628800 DO 3 I=1,3 DO3I=1.3 DO3I 1.3

More information

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

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。 ソフトウェア基礎演習課題 文法理解度確認範囲 問題 1 データ型 ( 変数, データ型 ) 問題 2 制御構造 (switch 文 ) 問題 3 制御構造 (while 文 ) 問題 4 制御構造と配列 ( 総和 ) 問題 5 制御構造と配列 ( 総和, 平均 ) 問題 6 データ型と各種演算子 ( 文字列, 検索 ) 問題 7 クラスの定義 ( メソッドの定義, コンストラクタの定義, キャスト

More information

JavaプログラミングⅠ

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

More information

(1) プログラムの開始場所はいつでも main( ) メソッドから始まる 順番に実行され add( a,b) が実行される これは メソッドを呼び出す ともいう (2)add( ) メソッドに実行が移る この際 add( ) メソッド呼び出し時の a と b の値がそれぞれ add( ) メソッド

(1) プログラムの開始場所はいつでも main( ) メソッドから始まる 順番に実行され add( a,b) が実行される これは メソッドを呼び出す ともいう (2)add( ) メソッドに実行が移る この際 add( ) メソッド呼び出し時の a と b の値がそれぞれ add( ) メソッド メソッド ( 教科書第 7 章 p.221~p.239) ここまでには文字列を表示する System.out.print() やキーボードから整数を入力する stdin.nextint() などを用いてプログラムを作成してきた これらはメソッドと呼ばれるプログラムを構成する部品である メソッドとは Java や C++ などのオブジェクト指向プログラミング言語で利用されている概念であり 他の言語での関数やサブルーチンに相当するが

More information

2

2 問題 次の設問に答えよ 設問. Java のソースコードをコンパイルするコマンドはどれか a) java b) javac c) javadoc d) javaw 設問. Java のバイトコード ( コンパイル結果 ) を実行するコマンドはどれか a) java b) javac c) javadoc d).jar 設問. Java のソースコードの拡張子はどれか a).c b).java c).class

More information

Assignment_.java 課題 : 転置行列 / class Assignment_ public static void main(string[] args) int i,j; int[][] array = 1,,,,,,,,,,,,,1,1,; 行 列行列 i

Assignment_.java 課題 : 転置行列 / class Assignment_ public static void main(string[] args) int i,j; int[][] array = 1,,,,,,,,,,,,,1,1,; 行 列行列 i 1 1 0 1 Assignment_1.java 課題 1: チェッカー / class Assignment_1 public static void main(string[] args) int i,j; チェッカー用の 次元配列 int[][] checker=new int[][]; チェッカーパターンを書き込む for(i=0;i

More information

Week 1 理解度確認クイズ解答 解説 問題 1 (4 2 点 =8 点 ) 以下の各問いに答えよ 問題 bit 版の Windows8.1 に Java をインストールする時 必要なパッケージはどれか 但し Java のコンパイルができる環境をインストールするものとする 1. jdk

Week 1 理解度確認クイズ解答 解説 問題 1 (4 2 点 =8 点 ) 以下の各問いに答えよ 問題 bit 版の Windows8.1 に Java をインストールする時 必要なパッケージはどれか 但し Java のコンパイルができる環境をインストールするものとする 1. jdk Week 1 理解度確認クイズ解答 解説 問題 1 (4 2 点 =8 点 ) 以下の各問いに答えよ 問題 1-1 32bit 版の Windows8.1 に Java をインストールする時 必要なパッケージはどれか 但し Java のコンパイルができる環境をインストールするものとする 1. jdk-8u65-windows-i586.exe 2. jre-8u65-windows-i586.exe

More information

Prog1_3rd

Prog1_3rd 2019 年 10 月 10 日 ( 木 ) 実施 プログラムの制御構造 1960 年代後半にダイクストラが提唱した構造化プログラミングという考え方では, 手続き型のプログラムを記述する際には, 順次, 選択, 反復という標準的な制御構造のみを用い, 先ずプログラムの概略構造を設計し, その大まかな単位を段階的に詳細化して処理を記述していく 順次構造順次構造とは, プログラム中の文を処理していく順に記述したものである

More information

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

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF pref : 2004/6/5 (11:8) pref : 2004/6/5 (11:8) pref : 2004/6/5 (11:8) 3 5 14 18 21 23 23 24 28 29 29 31 32 34 35 35 36 38 40 44 44 45 46 49 49 50 pref : 2004/6/5 (11:8) 50 51 52 54 55 56 57 58 59 60 61

More information

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

問題1 以下に示すプログラムは、次の処理をするプログラムである 問題 1 次のプログラムの出力結果を a~d の中から選べ public class Problem1 { int i=2; int j=3; System.out.println("i"+j); a) 23,b) 5,c) i3,d) ij 問題 2 次のプログラムの出力結果を a~d の中から選べ public class Problem2 { int a=6; if((a>=2)&&(a

More information

I java A

I java A I java 065762A 19.6.22 19.6.22 19.6.22 1 1 Level 1 3 1.1 Kouza....................................... 3 1.2 Kouza....................................... 4 1.3..........................................

More information

10/8 Finder,, 1 1. Finder MAC OS X 2. ( ) MAC OS X Java ( ) 3. MAC OS X Java ( ) / 10

10/8 Finder,, 1 1. Finder MAC OS X 2. ( ) MAC OS X Java ( ) 3. MAC OS X Java ( ) / 10 10/8 2015-10-08 URL : http://webct.kyushu-u.ac.jp, 10/8 1 / 10 10/8 Finder,, 1 1. Finder MAC OS X 2. ( ) MAC OS X Java ( ) 3. MAC OS X Java ( ) 1. 30 2 / 10 10/8 Finder 1 Figure : : Apple.com 2, 3 / 10

More information

ALG2012-A.ppt

ALG2012-A.ppt 21279 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/212/index.html (, )ε m = n C2 = n ( n 1) / 2 m = n ( n 1) 1 11 11 111 11 111 111 1111 1 1 11 1 11 11 111 4-dimentional

More information

Method(C 言語では関数と呼ぶ ) メソッドを使うと 処理を纏めて管理することができる 処理 ( メソッド ) の再実行 ( 再利用 ) が簡単にできる y 元々はC 言語の関数であり 入力値に対する値を 定義するもの 数学では F(x) = 2x + 1 など F(x)=2x+1 入力値 (

Method(C 言語では関数と呼ぶ ) メソッドを使うと 処理を纏めて管理することができる 処理 ( メソッド ) の再実行 ( 再利用 ) が簡単にできる y 元々はC 言語の関数であり 入力値に対する値を 定義するもの 数学では F(x) = 2x + 1 など F(x)=2x+1 入力値 ( Method(C 言語では関数と呼ぶ ) メソッドを使うと 処理を纏めて管理することができる 処理 ( メソッド ) の再実行 ( 再利用 ) が簡単にできる y 元々はC 言語の関数であり 入力値に対する値を 定義するもの 数学では F(x) = 2x + 1 など F(x)=2x+1 入力値 ( 引数 ) x が決まれば F(x) が決まる これを応用して 複雑な処理も 外面的にはひと固まりの処理として扱う

More information

ALG ppt

ALG ppt 2012 6 21 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2012/index.html 1 l l O(1) l l l 2 (123 ) l l l l () l H(k) = k mod n (k:, n: ) l l 3 4 public class MyHashtable

More information

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

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。 解答例 問題 1 変数 a が 3 以上でかつ 7 以下の場合 true と表示し そうでない場合は false と表示するプログラムである public class Prog061004_01 { int a; boolean b; a = Integer.parseInt(buf.readLine()); b = (a >= 3) && (a

More information

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

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 tutimura@mist.i.u-tokyo.ac.jp kaneko@ipl.t.u-tokyo.ac.jp http://www.misojiro.t.u-tokyo.ac.jp/ tutimura/sem3/ 2002 12 11 p.1/33 10/16 1. 10/23 2. 10/30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20

More information

プログラミング入門1

プログラミング入門1 プログラミング入門 1 第 5 回 繰り返し (while ループ ) 授業開始前に ログオン後 不要なファイルを削除し て待機してください Java 1 第 5 回 2 参考書について 参考書は自分にあったものをぜひ手元において自習してください 授業の WEB 教材は勉強の入り口へみなさんを案内するのが目的でつくられている これで十分という訳ではない 第 1 回に紹介した本以外にも良書がたくさんある

More information

untitled

untitled 2011 6 20 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2011/index.html tech.ac.jp/k1sakai/lecture/alg/2011/index.html html 1 O(1) O(1) 2 (123) () H(k) = k mod n

More information

Java updated

Java updated Java 2003.07.14 updated 3 1 Java 5 1.1 Java................................. 5 1.2 Java..................................... 5 1.3 Java................................ 6 1.3.1 Java.......................

More information

JavaプログラミングⅠ

JavaプログラミングⅠ Java プログラミング Ⅰ 4 回目演算子 今日の講義で学ぶ内容 演算子とオペランド 式 様々な演算子 代表的な演算子の使用例 演算子とオペランド 演算子 演算の種類です例えば + - * / 掛け算の記号は ではなく *( アスタリスク ) を使います割り算の記号は ではなく /( スラッシュ ) を使います オペランド 演算の対象です例えば 5( 値 ) num( 変数 ) 式 演算子とオペランドの組み合わせにより構成される数式です式は演算結果をもちます

More information

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

Java演習(4)   -- 変数と型 -- 50 20 20 5 (20, 20) O 50 100 150 200 250 300 350 x (reserved 50 100 y 50 20 20 5 (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics; (reserved public class Blocks1 extends

More information

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

問題1 以下に示すプログラムは、次の処理をするプログラムである 問題 1 次に示すプログラムは 配列 a の値を乱数で設定し 配列 a の値が 333 より大きく 667 以下の値 の合計値を求めるプログラムである 1 と 2 に適切なコードを記述してプログラムを完 成させよ class TotalNumber { public static void main(string[] args) { int[] a = new int[1000]; // 1 解答条件

More information

Prog1_2nd

Prog1_2nd 2019 年 10 月 3 日 ( 木 ) 実施浮動小数点数 Java 言語で実数を扱う場合, 実用的な計算には変数のデータ型としては,double 型を用いる 浮動小数点数とは, 実数を表す方式の一つで,2 進数の場合は例えば 1.101 2 3 ( 判り易さの為にここでは 2 や 3 は 10 進数で表記 ) の様な表記法である なお, 第 1 回の教材にあった, 単精度, 倍精度という用語で,

More information

untitled

untitled 2011 7 21 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2011/index.html tech.ac.jp/k1sakai/lecture/alg/2011/index.html html 1 5 2 3 4 - 5 .. 6 - 7 public class KnapsackBB

More information

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

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value = Part2-1-3 Java (*) (*).class Java public static final 1 class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value

More information

プログラミング入門1

プログラミング入門1 プログラミング入門 1 第 4 回 繰り返し (for ループ ) 授業開始前に ログオンして待機して ください Java 1 第 4 回 2 不要ファイルの掃除 前回デスクトップにファイルをダウンロードした場合 次のものを削除してください week03.zip デスクトップにファイルを置きすぎると コンピュータをシャットダウンできなくなります Java 1 第 4 回 3 授業を始めます 前回の課題は

More information

untitled

untitled 21174 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/211/index.html tech.ac.jp/k1sakai/lecture/alg/211/index.html html (, )ε m = n C2 = n ( n 1) / 2 m = n ( ( n

More information

JavaプログラミングⅠ

JavaプログラミングⅠ Java プログラミング Ⅰ 6 回目 if 文と if else 文 今日の講義で学ぶ内容 関係演算子 if 文と if~else 文 if 文の入れ子 関係演算子 関係演算子 ==,!=, >, >=,

More information

ex01.dvi

ex01.dvi ,. 0. 0.0. C () /******************************* * $Id: ex_0_0.c,v.2 2006-04-0 3:37:00+09 naito Exp $ * * 0. 0.0 *******************************/ #include int main(int argc, char **argv) double

More information

: : : TSTank 2

: : : TSTank 2 Java (8) 2008-05-20 Lesson6 Lesson5 Java 1 Lesson 6: TSTank1, TSTank2, TSTank3 java 2 car1 car2 Car car1 = new Car(); Car car2 = new Car(); car1.setcolor(red); car2.setcolor(blue); car2.changeengine(jet);

More information

ALG2012-F.ppt

ALG2012-F.ppt 2012 7 26 (sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2012/index.html 5 2 3 4 - 5 .. 6 - 7 public class KnapsackBB { // 0-1 private static double maxsofar; private

More information

JavaプログラミングⅠ

JavaプログラミングⅠ Java プログラミング Ⅰ 12 回目クラス 今日の講義で学ぶ内容 クラスとは クラスの宣言と利用 クラスの応用 クラス クラスとは 異なる複数の型の変数を内部にもつ型です 直観的に表現すると int 型や double 型は 1 1 つの値を管理できます int 型の変数 配列型は 2 5 8 6 3 7 同じ型の複数の変数を管理できます 配列型の変数 ( 配列変数 ) クラスは double

More information

グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { } S = a, a,, an の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しい

グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { } S = a, a,, an の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しい グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { S = a, a,, an 0 1 1 の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しいことを数学的帰納法で示しなさい 2. 文字列を列挙する再帰的アルゴリズムを構築しなさい 3. n = 4

More information

Java学習教材

Java学習教材 Java 2016/4/17 Java 1 Java1 : 280 : (2010/1/29) ISBN-10: 4798120987 ISBN-13: 978-4798120980 2010/1/29 1 Java 1 Java Java Java class FirstExample { public static void main(string[] args) { System.out.println("

More information

プログラミング入門1

プログラミング入門1 プログラミング入門 1 第 6 回 Switch 文 プロジェクトの持ち運び 授業開始前に ログオン後 不要なファイルを削除し て待機してください Java 1 第 6 回 2 前回のテーマ while 文を用いた繰り返し実行 for 文との使い分け 複雑な条件判定 && かつ または を使って Java 1 第 6 回 3 復習 : while 文はfor 文から 初期化式 を外に出し ステップを進める式

More information

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

アルゴリズムとデータ構造1 1 200972 (sakai.keiichi@kochi sakai.keiichi@kochi-tech.ac.jp) http://www.info.kochi ://www.info.kochi-tech.ac.jp/k1sakai/lecture/alg/2009/index.html 29 20 32 14 24 30 48 7 19 21 31 Object public class

More information

Prog1_6th

Prog1_6th 2019 年 10 月 31 日 ( 木 ) 実施配列同種のデータ型を有する複数のデータ ( 要素 ) を番号付けして, ひとまとまりの対象として扱うものを配列と呼ぶ 要素 point[0] point[1] point[2] point[3] point[4] 配列 配列の取り扱いに関して, 次のような特徴がある 1. プログラム中で用いる配列変数 ( 配列の本体を参照する参照型の変数 ) は必ず宣言しておく

More information

オブジェクト指向プログラミング・同演習 5月21日演習課題

オブジェクト指向プログラミング・同演習 5月21日演習課題 オブジェクト指向プログラミング 同演習 5 月 21 日演習課題 問題 1 配列の例外処理例外が発生する可能性のある処理を try で囲み その後に catch で例外を捕捉します 例外処理の終了処理として finally が行われます これは書かなくて自動的に行われます 提出課題 1 (Kadai052301.java) 以下のプログラムは例外処理をしていない ArrayIndexOutOfBoundsException

More information

JavaプログラミングⅠ

JavaプログラミングⅠ Java プログラミング Ⅰ 8 回目 for 文 今日の講義で学ぶ内容 for 文 変数のスコープ for 文の入れ子 繰り返し文 1 for 文 for 文最初に一度だけ初期化の式を処理します条件が true の場合 文を実行し 更新の式を処理して繰り返します条件が false の場合 for 文を終了します 条件は boolean 型で 関係演算子で表現される式などを記述します for( 初期化の式

More information

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

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value = Part2-1-3 Java (*) (*).class Java public static final 1 class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value

More information

プログラミングA

プログラミングA プログラミング A 第 10 回 演習 2015 年 6 月 29 日 東邦大学金岡晃 本日の内容 中間テストの解説 演習 1 2015/6/29 プログラミング A 中間テスト解説 : 問 1 < 問 1> 下記の命令が実行された後の a の値を書きなさい ( 省略 ). int a=13; 答え : 13 2 中間テスト解説 : 問 2 < 問 2> 下記の命令が実行された後の a の値を書きなさい

More information

問題 01 以下は コンソールより年齢を入力させ その年齢にあった料金を表示するプログラムである 年齢ごとの金額は以下の通りである 年齢の範囲金額 0 歳以上 6 歳以下 120 円 7 歳以上 65 歳未満 200 円 65 歳以上無料 package j1.exam02; import java

問題 01 以下は コンソールより年齢を入力させ その年齢にあった料金を表示するプログラムである 年齢ごとの金額は以下の通りである 年齢の範囲金額 0 歳以上 6 歳以下 120 円 7 歳以上 65 歳未満 200 円 65 歳以上無料 package j1.exam02; import java 問題 01 以下は コンソールより年齢を入力させ その年齢にあった料金を表示するプログラムである 年齢ごとの金額は以下の通りである 年齢の範囲金額 0 歳以上 6 歳以下 120 円 7 歳以上 65 歳未満 200 円 65 歳以上無料 public class Ex0201 { System.out.print("input> "); int input = Integer.parseInt(reader.readLine());

More information

文字列操作と正規表現

文字列操作と正規表現 文字列操作と正規表現 オブジェクト指向プログラミング特論 2018 年度只木進一 : 工学系研究科 2 文字列と文字列クラス 0 個以上の長さの文字の列 Java では String クラス 操作 文字列を作る 連結する 文字列中に文字列を探す 文字列中の文字列を置き換える 部分文字列を得る 3 String クラス 文字列を保持するクラス 文字列は定数であることに注意 比較に注意 == : オブジェクトとしての同等性

More information

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy オブジェクト指向プログラミング演習 2010/10/27 演習課題 スレッド ( その 2) 同期処理 結果不正 デッドロック 前回のスレッドの演習では 複数のスレッドを実行し 一つのプログラムの中の違う処理を同時に実行し た ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする )

More information

JAVA とテンプレート

JAVA とテンプレート JAVA とテンプレート 序論 : コンテナ 他のクラスのオブジェクトを保存するものをコンテナ (Container) と呼ぶ 集合 リスト 表 コンテナに求められる機能 追加 削除 参照 要素の比較 並べ替え 要素のクラスが不明では 比較できない 要素が想定しているクラスのものかの判定 テンプレート以前の対応方法 コンテナ設計時に 保存されるクラスを特定してコンテナをコードする 保存されるクラスごとに作成しなければならない

More information

class TestPrimitiveType{ public static

class TestPrimitiveType{ public static プリミティブ型 ( 基本データ型 ) プリミティブ型 ( 基本データ型 ) 浮動小数点の数値範囲が正負対称でないのは, べき乗表示にバイアスがかかっているのと 0 以外すべて最上位 bit が 1 と決まっているので最上位を省略しているためである 分類 型 ビット数数値の範囲 符号付き整数 byte 8-2 7 ~+2 7-1(-128~+127) 符号付き整数 short 16-2 15 ~+2

More information

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

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 2 2013 4 16 2.1............................... 2 1 2.2 Java......................... 2 2 2.3............. 2 2 2.4................................ 2 4 2.5............................ 2 5 2.6............................

More information

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I  Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~alse I Exercise on Programming I http://bit.ly/oitprog1 1, 2 of 14 ( RD S ) I 1, 2 of 14 1 / 44 Ruby Ruby ( RD S ) I 1, 2 of 14 2 / 44 7 5 9 2 9 3 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 ( RD S ) I 1, 2

More information

Writing Explain Tracing2 Sequence Data Tracing1 Modification2 Modification1 Basics 1 Fig. 1 Hierarchy of skill related to programming(hypothesis) Modi

Writing Explain Tracing2 Sequence Data Tracing1 Modification2 Modification1 Basics 1 Fig. 1 Hierarchy of skill related to programming(hypothesis) Modi 1 2 1 Modification Modification1, Modification2 1) Basics, Sequence, Tracing1, Tracing2, Explain, Writing 8 Modification Modification Research on programming skill hierarchy Mitsuo Yamamoto, 1 Takayuki

More information

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A Java 3 p.1 3 Java Java if for while C 3.1 if Java if C if if ( ) 1 if ( ) 1 else 2 1 1 2 2 1, 2 { Q 3.1.1 1. int n = 2; if (n

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション オブジェクト指向 プログラミング演習 第 2 回クラス インスタンス メソッド フィールド コンストラクタ ICPC の宣伝 国際大学対抗プログラミングコンテスト 3 人一組のチームでプログラムを書く速さを競う 国内予選 : ネットワーク上で 6 月末 ~7 月頭 アジア地区予選 : 日本国内で秋に開催 世界大会 :2020 年は 6 月にモスクワで 参加登録締切 : 国内予選の 2~3 週間前 今年は

More information

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

Microsoft PowerPoint - netpro_2015_02.ppt [互換モード] ネットワークプログラミング 21004 2 号館 10 階 第 2 回 2014/9/29 岩井将行 ( 通称福山のまさゆき ) 2015/9/29 1 授業資料 http://www.cps.im.dendai.ac.jp 2015/9/29 2 講師紹介 http://cps.im.dendai.ac.jp/index.php?members%2fiwai ac php?members%2fiwai

More information

第二回独習 Java ゼミ 第二章クラスとメソッド 2.1 メソッドの構造 2.2 静的メソッドと静的変数の概要 2.3 インスタンスメソッドとインスタンス変数の概要 2.4 Integerクラス 2006/04/19 神津健太

第二回独習 Java ゼミ 第二章クラスとメソッド 2.1 メソッドの構造 2.2 静的メソッドと静的変数の概要 2.3 インスタンスメソッドとインスタンス変数の概要 2.4 Integerクラス 2006/04/19 神津健太 第二回独習 Java ゼミ 第二章クラスとメソッド 2.1 メソッドの構造 2.2 静的メソッドと静的変数の概要 2.3 インスタンスメソッドとインスタンス変数の概要 2.4 Integerクラス 2006/04/19 神津健太 2.1 メソッドの構造 メソッドとは プログラムステータメントの集合体 Java の基本的な実行単位 クラスの一部 メソッドの外部にプログラムコードを置いたり クラスの外部にメソッドを置くことはできない

More information

プログラムの基本構成

プログラムの基本構成 Java 入門 この 2 回 ( 今回と次回 ) が勝負だ! プログラムは自転車の練習と同じだ! 今日の予定先ず プログラムの構造を学び (p.2~6) jcpad でプログラム ( 計算機実習室 ) 戻ってきてプログラムの解読手書きプログラムを TA にみてもらい OK の出た人は計算機実習室でプログラム作成し実行実行結果を TA がチェックして帰り プログラムの基本構成 Step1: 入力 Step2:

More information

プログラミング入門1

プログラミング入門1 プログラミング入門 1 第 3 回 条件分岐 授業開始前に ログオンして待機して ください Java 1 第 3 回 2 不要ファイルの掃除 前回デスクトップにファイルをダウンロードした場合 次のものを削除してください week02.zip デスクトップにファイルを置きすぎると コンピュータをシャットダウンできなくなります Java 1 第 3 回 3 授業を始めます 前回の課題は うまくできましたか?

More information

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

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 Java (7) 2008-05-20 1 Lesson 5 1.1 5 3 = (1) 1 m 3 /s 1 2 3 10 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 java 2 1. 2. 3. 4. 3 2 1.3 i =1, 2, 3 V i (t) 1 t h i (t) i F, k

More information

JavaプログラミングⅠ

JavaプログラミングⅠ Java プログラミング Ⅰ 7 回目 switch 文と論理演算子課題 1. 複数の選択肢から 1 つを選択するコードを switch 文で作りなさい 質問と解説は各自で設定しましょう ヒント : 選択肢の番号 1~4 で分岐するように switch 文を用いましょう あなたの好みの色は何色ですか? 1. 赤. 青. 黄 4. 緑 青の好きなあなたは沈着冷静な方です あなたの好みの色は何色ですか?

More information

情報実習Ⅱ

情報実習Ⅱ 情報実習 Ⅱ 第 7 回 ( これまでの復習 ) 課題資料 Java のクラスの概形 クラス フィールドコンストラクタメソッド main メソッドローカル変数宣言オブジェクト生成オブジェクトへのメッセージ ( メソッド呼び出し ) 変数 : 基本型, 参照型 これまでの 習得事項 まだ初歩的な内容だけだが これらを利用するだけでも多くの実用的なプログラムが記述できる キーボード入力 : Scanner

More information

‚æ4›ñ

‚æ4›ñ ( ) ( ) ( ) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 (OUS) 9 26 1 / 28 ( ) ( ) ( ) A B C D Z a b c d z 0 1 2 9 (OUS) 9

More information

text_08.dvi

text_08.dvi C 8 12 6 6 8 Java (3) 1 8.1 8 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 8.2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

More information