0
public class BioHomework {
  public static void main(String[] args) {
    if(args.length < 2) {
       throw new IllegalArgumentException("two args required");
    }
    String sequence = args[1];
    if (!sequence.toLowerCase().matches("[atgc]{10,20}")){
      throw new IllegalArgumentException("second arg should be 'atgc' string between 10 and 20 characters");
    }
    if ("u".equals(args[0])) {
      System.out.println(sequence.toUpperCase());
    } else if ("l".equals(args[0])) {
      System.out.println(sequence.toLowerCase());
    } else {
      throw new IllegalArgumentException("first argument must be either 'u' or 'l'");
    }

  }
}

コマンドライン引数を指定して、DNAシーケンスを大文字と小文字で出力するにはどうすればよいですか。上記のコードでは、メッセージのみが表示されます。

4

1 に答える 1

0

大文字または小文字の文字を受け入れるには、正規表現を変更するだけです。から

[atgc]{10,20}

[aAtTgGcC]{10,20}
于 2013-02-28T18:48:09.323 に答える