publicstaticvoidmain(String[] args) { BufferedReaderreader=newBufferedReader(newInputStreamReader(System.in)); // Reading data using readLine Stringname=null; try { while (!"0".equals(name)) { name = reader.readLine(); System.out.println(name); }
Exception in thread "main" java.lang.NullPointerException at com.lin.springlearn.service.PrimeNumber.main(Test.java:37)
使用命令行参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
public static void main(String[] args) { // check if length of args array is // greater than 0 if (args.length > 0) { System.out.println( "The command line arguments are:"); // iterating the args array and printing // the command line arguments for (String val : args) System.out.println(val); } else System.out.println("No command line " + "arguments found."); }