Advertisement
cd62131

2 times

Apr 6th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.71 KB | None | 0 0
  1. public class Kadai1r {
  2.   public static void main(String[] args) {
  3.     if (!isArgumentCount(args, 1)) System.exit(1);
  4.     int a = convertInteger(args[0]);
  5.     System.out.println(2 * a);
  6.   }
  7.  
  8.   private static boolean isArgumentCount(String[] args, int i) {
  9.     if (args.length != i) {
  10.       System.err.println("error: コマンドライン引数は" + i + "個です");
  11.       return false;
  12.     }
  13.     return true;
  14.   }
  15.  
  16.   private static int convertInteger(String string) {
  17.     int ret = -1;
  18.     try {
  19.       ret = Integer.parseInt(string);
  20.     }
  21.     catch (NumberFormatException e) {
  22.       System.err.println("error: 整数のみを入力してください");
  23.       System.exit(1);
  24.     }
  25.     return ret;
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement