zoukankan      html  css  js  c++  java
  • java 中关于 Exception 的几种打印输出 和 StringTokenizer 的用法

    今天做 SSD 3 的 Quiz 1,试了一下抛出异常时的效果(详见 ICarnegieInfoApplication.java):
                nfe.printStackTrace();//写一大段
                // System.out.println(nfe.getMessage()); the output result was just "For input string "aa""
                // System.out.println(nfe.getCause()); output "null"
                // System.out.println(nfe.getLocalizedMessage()); the same as .getMessage
                //stdErr.println(nfe.getMessage());// the same as .getMessage


    然后就是 StringTokenizer 的用法。开始 vivizhyy 只凭着印象写参数,结果分出来的个数不对。
    开始写的是 StringTokenizer stringTokenizer = new StringTokenizer(":");
    这样分出来的还是会有那个 “:” 在结果中,查过 api 后,加上需要被分的字符串作为第一个参数,这样。那个“:” 就会被分掉了。(详见 SecondsCalculator)

    ps.
    StringTokenizer(String str)
     Constructs a string tokenizer for the specified string.
    StringTokenizer(String str,String delim)
     Constructs a string tokenizer for the specified string.
    StringTokenizer(String str,String delim,boolean returnDelims)
     Constructs a string tokenizer for the specified string.
    第三种用法 vivizhyy 还没玩过还。

    还有就是 StringTokenizer 这个类里面有个方法:countTokens()Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

    恩,自己把 Quiz 做完了,好高兴。

  • 相关阅读:
    LCA + 二分(倍增)
    Educational Codeforces Round 5
    BNU 51276
    POJ 1511
    hdu2121
    最小树形图(朱刘算法)
    Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
    Educational Codeforces Round 1(C. Nearest vectors)
    POJ-2785 4 Values whose Sum is 0(折半枚举 sort + 二分)
    POJ 1661Help Jimmy(逆向DP Or 记忆化搜索 Or 最短路径)
  • 原文地址:https://www.cnblogs.com/vivizhyy/p/3394932.html
Copyright © 2011-2022 走看看