2015年4月16日木曜日

3つの整数を入力して最小値を表示するjavaプログラム

Javaバイブルシリーズ Java入門 P143応用課題5.3.2

------
import java.io.*;
public class Minimum {
 public static void main(String[] args) throws IOException {
 
  final String MIN_MESSAGE = "最大値は";
  String max = "";
 
  BufferedReader br =
          new BufferedReader(new InputStreamReader(System.in));
 
 
  System.out.print("xを入力>");
  int x = Integer.parseInt(br.readLine());
  System.out.print("yを入力>");
  int y = Integer.parseInt(br.readLine());
  System.out.print("zを入力>");
  int z = Integer.parseInt(br.readLine());
 
  int minValue = x;
  if (y < x) {
   minValue = y;
     }
  if (z < y && z < x) {
   minValue = z;
  }
  System.out.println(MIN_MESSAGE + minValue);


 }
}
------

実行結果
------
>java Minimum
xを入力>4
yを入力>5
zを入力>3
最大値は3
 -- Press any key to exit (Input "c" to continue) --
------

3つの整数を入力して最大値を表示するjavaプログラムパターン2

Javaバイブルシリーズ Java入門 P143 応用課題5.3.1


------
import java.io.*;
public class Maximum1 {
 public static void main(String[] args) throws IOException {
 
  final String MAX_MESSAGE = "最大値は";
  String max = "";
 
  BufferedReader br =
          new BufferedReader(new InputStreamReader(System.in));
 
 
  System.out.print("xを入力>");
  int x = Integer.parseInt(br.readLine());
  System.out.print("yを入力>");
  int y = Integer.parseInt(br.readLine());
  System.out.print("zを入力>");
  int z = Integer.parseInt(br.readLine());
 
  int maxValue = x;
  if (y > x) {
   maxValue = y;
     }
  if (z > y && z > x) {
   maxValue = z;
  }
  System.out.println(MAX_MESSAGE + maxValue);


 }
}
------

実行結果
------
>java Maximum1
xを入力>4
yを入力>3
zを入力>5
最大値は5
 -- Press any key to exit (Input "c" to continue) --
------

3つの整数を入力して最大値を表示するjavaプログラムパターン1

Javaバイブルシリーズ Java入門 P142演習問題5.3

------
import java.io.*;
public class Maximum {
 public static void main(String[] args) throws IOException {
 
  final String MAX_MESSAGE = "最大値は";
  String max = "";
 
  BufferedReader br =
          new BufferedReader(new InputStreamReader(System.in));
 
 
  System.out.print("xを入力>");
  int x = Integer.parseInt(br.readLine());
  System.out.print("yを入力>");
  int y = Integer.parseInt(br.readLine());
  System.out.print("zを入力>");
  int z = Integer.parseInt(br.readLine());
 
  if(y > x || z > x) {
   if(z > y) {
    max = MAX_MESSAGE + z;
   } else {
    max = MAX_MESSAGE + y;
   }
     } else {
   if (z > x) {
    max = MAX_MESSAGE + z;
   } else {
    max = MAX_MESSAGE + x;
   }
  }
  System.out.println(max);


 }
}
------

実行結果
------
>java Maximum
xを入力>3
yを入力>4
zを入力>5
最大値は5
 -- Press any key to exit (Input "c" to continue) --
------

50点以上のときは合格と表示,50点未満ならあと何点で合格ですと表示するjavaプログラム

Javaバイブルシリーズ Java入門 P140 演習問題5.2

------
import java.io.*;
public class PassJudge {
 public static void main(String[] args) throws IOException {
  final int GOKAKU_TEN = 50;
 
  BufferedReader br =
          new BufferedReader(new InputStreamReader(System.in));
  String buf;
 
  System.out.println("終了は[Enter]だけを入力");
  System.out.print("点数入力>");
  while (!(buf = br.readLine()) .equals("")) {
  
   int ten = Integer.parseInt(buf);
   String message = "";
  
   if(ten < 50){
    int fusoku = -1 * (ten - 50);
    message = "あと" + fusoku + "点で合格です";
   } else {
    message = "合格です";
   }
       System.out.println(message);
       System.out.print("整数入力>");
      }
 }
}
------

実行結果
------
>java PassJudge
終了は[Enter]だけを入力
点数入力>51
合格です
整数入力>40
あと10点で合格です
整数入力>
 -- Press any key to exit (Input "c" to continue) --
------

入力された整数があらかじめ指定された整数の倍数かどうかを判定するjavaプログラム

Javaバイブルシリーズ Java入門 P140応用課題5.1.1

下記の例は3の倍数かどうかを判定するプログラム
------
import java.io.*;
public class MultipleOfX {
 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);
   int x = 3;
  
   if(num % x == 0){
    System.out.println(num + "は" + x + "の倍数です");
   } else {
    System.out.println(num + "は" + x + "の倍数ではありません");
   }
       System.out.print("整数入力>");
      }
 }
}
------

実行結果
------
>java MultipleOfX
終了は[Enter]だけを入力
整数入力>3
3は3の倍数です
整数入力>4
4は3の倍数ではありません
整数入力>5
5は3の倍数ではありません
整数入力>
 -- Press any key to exit (Input "c" to continue) --
------

入力された整数が奇数か偶数かをチェックするjavaプログラム

参考
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月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]#
------




現在原因を調査中。