参考
Javaバイブルシリーズ Java入門 P139演習5.1
------
import java.io.*;
public class OddEvenJudge {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String buf;
System.out.println("終了は[Enter]だけを入力");
System.out.print("整数入力>");
while (!(buf = br.readLine()) .equals("")) {
int num = Integer.parseInt(buf);
if(num % 2 == 0){
System.out.println(num + "は偶数です");
} else {
System.out.println(num + "は奇数です");
}
System.out.print("整数入力>");
}
}
}
------
実行結果
------
>java OddEvenJudge
終了は[Enter]だけを入力
整数入力>6
6は偶数です
整数入力>5
5は奇数です
整数入力>
-- Press any key to exit (Input "c" to continue) --
------
2015年4月16日木曜日
2015年4月12日日曜日
BINDの起動に失敗cetnos6.6
http://centossrv.com/bind.shtml
を参考にBINDを構築中。
しかし
BINDの起動に失敗
ホスト名は
centos.com
とする
------
[root@centos etc]# /etc/rc.d/init.d/named start
named を起動中:
Error in named configuration:
zone localhost.localdomain/IN: loaded serial 0
zone localhost/IN: loaded serial 0
zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
zone 0.in-addr.arpa/IN: loaded serial 0
zone centos.com/IN: loaded serial 2011062001
zone 0.168.192.in-addr.arpa/IN: loaded serial 2011062001
zone centos.com/IN: loading from master file centos.com.db.wan failed: file not found
zone centos.com/IN: not loaded due to errors.
external/centos.com/IN: file not found
[失敗]
[root@centos etc]#
------
現在原因を調査中。
を参考にBINDを構築中。
しかし
BINDの起動に失敗
ホスト名は
centos.com
とする
------
[root@centos etc]# /etc/rc.d/init.d/named start
named を起動中:
Error in named configuration:
zone localhost.localdomain/IN: loaded serial 0
zone localhost/IN: loaded serial 0
zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
zone 0.in-addr.arpa/IN: loaded serial 0
zone centos.com/IN: loaded serial 2011062001
zone 0.168.192.in-addr.arpa/IN: loaded serial 2011062001
zone centos.com/IN: loading from master file centos.com.db.wan failed: file not found
zone centos.com/IN: not loaded due to errors.
external/centos.com/IN: file not found
[失敗]
[root@centos etc]#
------
現在原因を調査中。
2015年3月21日土曜日
centos 6でDiCE設定実施時setarchコマンドでエラー
http://centossrv.com/domain-ieserver.shtml
を参照してDiCE設定を実施。
しかしエラー発生
-----
# setarch `uname -m` /usr/local/bin/DiCE/diced
setarch: /usr/local/bin/DiCE/diced: 縺昴・繧医≧縺ェ繝輔ぃ繧、繝ォ繧・ョ繧」繝ャ繧ッ繝医Μ縺ッ縺ゅj縺セ縺帙s
------
調べると以下のコマンドを実行するとよいとのこと
------
# yum install ld-linux.so.2
------
参照元
http://centossrv.com/bbshtml/webpatio/2332.shtml
その後再度setarchコマンドを実行すると成功。
------
# setarch `uname -m` /usr/local/bin/DiCE/diced
=-=-=- DiCE DynamicDNS Client -=-=-=
Version 0.19 for Japanese
Copyright(c) 2001 sarad
:
------
を参照してDiCE設定を実施。
しかしエラー発生
-----
# setarch `uname -m` /usr/local/bin/DiCE/diced
setarch: /usr/local/bin/DiCE/diced: 縺昴・繧医≧縺ェ繝輔ぃ繧、繝ォ繧・ョ繧」繝ャ繧ッ繝医Μ縺ッ縺ゅj縺セ縺帙s
------
調べると以下のコマンドを実行するとよいとのこと
------
# yum install ld-linux.so.2
------
参照元
http://centossrv.com/bbshtml/webpatio/2332.shtml
その後再度setarchコマンドを実行すると成功。
------
# setarch `uname -m` /usr/local/bin/DiCE/diced
=-=-=- DiCE DynamicDNS Client -=-=-=
Version 0.19 for Japanese
Copyright(c) 2001 sarad
:
------
2015年2月22日日曜日
文字列をアルファベット順(辞書式)に比較して先に現れる文字列を表示するプログラム
参考 Javaバイブルシリーズ Java入門 Java 7版
P128 確認問題 5.5
------
import java.io.*;
public class DictionaryComp {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String appear = "先に現れる文字列:";
System.out.print("文字列1>");
String str1 = br.readLine();
System.out.print("文字列2>");
String str2 = br.readLine();
if (str1.compareTo(str2) < 0) {
appear += str1;
} else if (str1.compareTo(str2) > 0) {
appear += str2;
} else {
appear = "一致:" + str1 + "と" + str2;
}
System.out.println(appear);
}
}
------
実行結果
------
>java DictionaryComp
文字列1>baseboll
文字列2>bus
先に現れる文字列:baseboll
-- Press any key to exit (Input "c" to continue) --
------
P128 確認問題 5.5
------
import java.io.*;
public class DictionaryComp {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String appear = "先に現れる文字列:";
System.out.print("文字列1>");
String str1 = br.readLine();
System.out.print("文字列2>");
String str2 = br.readLine();
if (str1.compareTo(str2) < 0) {
appear += str1;
} else if (str1.compareTo(str2) > 0) {
appear += str2;
} else {
appear = "一致:" + str1 + "と" + str2;
}
System.out.println(appear);
}
}
------
実行結果
------
>java DictionaryComp
文字列1>baseboll
文字列2>bus
先に現れる文字列:baseboll
-- Press any key to exit (Input "c" to continue) --
------
2015年2月11日水曜日
入力点数が70点以上なら"合格",70点未満なら"不合格"と表示するプログラム
参考 Javaバイブルシリーズ Java入門 Java 7版
P121 確認問題 5.3
------
import java.io.*;
public class PassJudge02 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("点数を入力>");
int ten = Integer.parseInt(br.readLine());
if (ten < 70) {
System.out.println("不合格です");
} else {
System.out.println("合格です");
}
}
}
-----
結果は以下
パターン1
-----
>java PassJudge02
点数を入力>70
合格です
-- Press any key to exit (Input "c" to continue) --
-----
パターン2
-----
>java PassJudge02
点数を入力>69
不合格です
-- Press any key to exit (Input "c" to continue) --
-----
P121 確認問題 5.3
------
import java.io.*;
public class PassJudge02 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("点数を入力>");
int ten = Integer.parseInt(br.readLine());
if (ten < 70) {
System.out.println("不合格です");
} else {
System.out.println("合格です");
}
}
}
-----
結果は以下
パターン1
-----
>java PassJudge02
点数を入力>70
合格です
-- Press any key to exit (Input "c" to continue) --
-----
パターン2
-----
>java PassJudge02
点数を入力>69
不合格です
-- Press any key to exit (Input "c" to continue) --
-----
2015年2月10日火曜日
70以上を入力したら「合格です」と表示するプログラム
参考
Javaバイブルシリーズ Java入門 Java 7版 P116 確認問題5.2
-------
import java.io.*;
public class PassJudge01 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("点数を入力>");
int ten = Integer.parseInt(br.readLine());
if (ten >= 70) {
System.out.println("合格です");
}
}
}
-------
コンパイルと実行結果
パターン1
------
>java PassJudge01
点数を入力>70
合格です
-- Press any key to exit (Input "c" to continue) --
------
パターン2
------
>java PassJudge01
点数を入力>64
-- Press any key to exit (Input "c" to continue) --
------リーズ Java入門 Java 7
Javaバイブルシリーズ Java入門 Java 7版 P116 確認問題5.2
-------
import java.io.*;
public class PassJudge01 {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("点数を入力>");
int ten = Integer.parseInt(br.readLine());
if (ten >= 70) {
System.out.println("合格です");
}
}
}
-------
コンパイルと実行結果
パターン1
------
>java PassJudge01
点数を入力>70
合格です
-- Press any key to exit (Input "c" to continue) --
------
パターン2
------
>java PassJudge01
点数を入力>64
-- Press any key to exit (Input "c" to continue) --
------リーズ Java入門 Java 7
2015年1月26日月曜日
掛け算の九九を表示するプログラム
参考
javaバイブルシリーズ Java入門
P109 演習問題4.5より
以下のような九九表を表示させるプログラムをfor文とwhile文のプログラムで作成しろという問題にチャレンジ
***********
>java Kuku??
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
***********
P102 確認問題4.2より
こんなプログラムがあった。
------
public class Trace3 {
public static void main(String[] args) {
for (int i = 1; i < 4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(" " + (i * j));
}
System.out.println();
}
}
}
------
実行結果は以下
******
>java Trace3
1
2 4
3 6 9
******
Trace3.javaを編集すれば、九九表がとけそうだ。
そして編集して何度かトライアンドエラーを実施してfor文のパターンは完成
------
public class Kuku2 {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
System.out.print(" " + (i * j));
}
System.out.println();
}
}
}
------
実行結果
******
>java Kuku2
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
******
続いてwhile文で作成
P88よりfor文とwhile文の相違点をチェック
whileの場合
---------------------
i = 1; // ④ iを1に初期化
while (i <= 10) { // ⑤ iが10以下のとき繰り返す
sum += i; // ⑥ 累計エリアにiを加算
i++; // ⑦ iをカウントアップ
}
---------------------
forの場合
---------------------
for (i = 1; i <= 10; i++) { // ④、⑤、⑦
sum += i; // ⑥ 累計エリアにiを加算
}
---------------------
何度かトライアンドエラーを繰り返し、while文のパターンも完成。
ポイントは上記④のように初期化の宣言を追記したこと。ついきしないとコンパイルでエラー。
------
public class Kuku1 {
public static void main(String[] args) {
int i;
int j;
i = 1;
while (i < 10) {
j = 0;
while (j < 9) {
j++;
System.out.print(" " + (i * j));
}
i++;
System.out.println();
}
}
}
------
実行結果
******
>java Kuku1
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
******
javaバイブルシリーズ Java入門
P109 演習問題4.5より
以下のような九九表を表示させるプログラムをfor文とwhile文のプログラムで作成しろという問題にチャレンジ
***********
>java Kuku??
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
***********
P102 確認問題4.2より
こんなプログラムがあった。
------
public class Trace3 {
public static void main(String[] args) {
for (int i = 1; i < 4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(" " + (i * j));
}
System.out.println();
}
}
}
------
実行結果は以下
******
>java Trace3
1
2 4
3 6 9
******
Trace3.javaを編集すれば、九九表がとけそうだ。
そして編集して何度かトライアンドエラーを実施してfor文のパターンは完成
------
public class Kuku2 {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
System.out.print(" " + (i * j));
}
System.out.println();
}
}
}
------
実行結果
******
>java Kuku2
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
******
続いてwhile文で作成
P88よりfor文とwhile文の相違点をチェック
whileの場合
---------------------
i = 1; // ④ iを1に初期化
while (i <= 10) { // ⑤ iが10以下のとき繰り返す
sum += i; // ⑥ 累計エリアにiを加算
i++; // ⑦ iをカウントアップ
}
---------------------
forの場合
---------------------
for (i = 1; i <= 10; i++) { // ④、⑤、⑦
sum += i; // ⑥ 累計エリアにiを加算
}
---------------------
何度かトライアンドエラーを繰り返し、while文のパターンも完成。
ポイントは上記④のように初期化の宣言を追記したこと。ついきしないとコンパイルでエラー。
------
public class Kuku1 {
public static void main(String[] args) {
int i;
int j;
i = 1;
while (i < 10) {
j = 0;
while (j < 9) {
j++;
System.out.print(" " + (i * j));
}
i++;
System.out.println();
}
}
}
------
実行結果
******
>java Kuku1
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
******
登録:
投稿 (Atom)