init
This commit is contained in:
18
Question17-Exception/src/PTra17_01.java
Normal file
18
Question17-Exception/src/PTra17_01.java
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* PTra15_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra17_01 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String str = null;
|
||||
|
||||
/*
|
||||
* TODO このプログラムを実行するとNullPointerExceptionが発生します。
|
||||
* 例外処理を行なって、例外処理が発生しました と表示されるようにプログラムを変更してください
|
||||
*/
|
||||
String[] list = str.split(",");
|
||||
}
|
||||
}
|
||||
19
Question17-Exception/src/PTra17_02.java
Normal file
19
Question17-Exception/src/PTra17_02.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* PTra15_02.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra17_02 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* commonパッケージのThrowExceptionUtilクラスから
|
||||
* countDownメソッドを引数 10 で呼び出してください
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
26
Question17-Exception/src/PTra17_03.java
Normal file
26
Question17-Exception/src/PTra17_03.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* PTra15_03.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra17_03 {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* NumberFormatExceptionが発生 が表示されるように、
|
||||
* 以下の処理を書き換えてください
|
||||
*/
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
|
||||
} catch (NullPointerException e) {
|
||||
System.out.println("NullPointerExceptionが発生");
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("NumberFormatExceptionが発生");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exceptionが発生");
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Question17-Exception/src/PTra17_04.java
Normal file
33
Question17-Exception/src/PTra17_04.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* PTra15_04.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
public class PTra17_04 {
|
||||
|
||||
// 1文字ごとに遅らせる秒数(ミリ秒)
|
||||
final static int SLEEP_TIME = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
numCheck(-10);
|
||||
} catch (Exception e) {
|
||||
System.out.println("例外が発生しました");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* TODO 以下のメソッドのエラーを解決して、
|
||||
* 実行時に 例外が発生しました と表示されるようにしてください。
|
||||
*/
|
||||
public static void numCheck(int num) {
|
||||
if (num < 0) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
System.out.println(num + "正の範囲の数値です");
|
||||
}
|
||||
|
||||
}
|
||||
32
Question17-Exception/src/common/ThrowExceptionUtil.java
Normal file
32
Question17-Exception/src/common/ThrowExceptionUtil.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
/**
|
||||
* 例外を発生させるようなメソッドを集めたクラスです
|
||||
* @author rhizome
|
||||
*
|
||||
*/
|
||||
public class ThrowExceptionUtil {
|
||||
|
||||
// 1文字ごとに遅らせる秒数(ミリ秒)
|
||||
final static int SLEEP_TIME = 1000;
|
||||
|
||||
/**
|
||||
* 渡された引数からカウントダウンを実施する
|
||||
* @param count
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static void countDown(int count) throws InterruptedException {
|
||||
for(int i = count; i >= 0; i--) {
|
||||
System.out.println(i);
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
}
|
||||
|
||||
System.out.println("カウントダウンを終了します");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user