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 回答