Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Kadai1r {
- public static void main(String[] args) {
- if (!isArgumentCount(args, 1)) System.exit(1);
- int a = convertInteger(args[0]);
- System.out.println(2 * a);
- }
- private static boolean isArgumentCount(String[] args, int i) {
- if (args.length != i) {
- System.err.println("error: コマンドライン引数は" + i + "個です");
- return false;
- }
- return true;
- }
- private static int convertInteger(String string) {
- int ret = -1;
- try {
- ret = Integer.parseInt(string);
- }
- catch (NumberFormatException e) {
- System.err.println("error: 整数のみを入力してください");
- System.exit(1);
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement