1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

文字列の長さで意図的に例外処理を発生させる

Posted at

例外処理を使って坂道メンバーの文字数チェックをする。

//例外処理を使って坂道メンバーの文字数チェックをする。
// 新規作成 2021/6/23
// Author  乃木坂好きのITエンジニア

import java.util.Scanner;

public class Sakamichi {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		System.out.println("好きな坂道メンバーを入力してください");
		String line = sc.nextLine();
		x(line);
		System.out.println("4文字以上のメンバーを入力しました ");

	}
	static void x(String name) throws Exception{
		int len = name.length();
		//メンバーの文字数が4字未満なら例外処理を実行する
		if(len < 4) {
			throw new Exception();
		}
		System.out.println(name);
	}
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?