1. fas
  2. 第二题
    package net.mindview.strings;
    
    import java.util.ArrayList;
    import java.util.List; /**
    * 无限循环
    */
    public class InfiniteRecursion {
    public InfiniteRecursion(){ }
    @Override
    public String toString() {
    return " InfiniteRecursion address" + super.toString() + "\n";
    }
    public static void main(String[] args) {
    List<InfiniteRecursion> list = new ArrayList<InfiniteRecursion>();
    for(int i=; i<; i++){
    list.add(new InfiniteRecursion());
    }
    System.out.println(list);
    }
    }
  3. fa
  4. 第四题
    package net.mindview.strings;
    
    import java.util.Formatter;
    
    public class Receipt {
    private double total = ;
    private Formatter f = new Formatter(System.out);
    public final int ITEM_WIDTH = ;
    public final int QTY_WIDTH = ;
    public final int PRICE_WIDTH = ;
    public final int PRICISION_FLOAT_WIDHT = ;
    public final int PRICISION_String_WIDHT = ;
    public final String TITLE_FORMAT = "%-" + ITEM_WIDTH + "s %" + QTY_WIDTH
    + "s %" + PRICE_WIDTH + "s\n";
    public final String PRICE_FORMAT = "%-" + ITEM_WIDTH + "."
    + PRICISION_String_WIDHT + "s %" + QTY_WIDTH + "d %" + PRICE_WIDTH
    + "." + PRICISION_FLOAT_WIDHT + "f\n";
    public final String TOTAL_FORMAT = "%-" + ITEM_WIDTH + "s %" + QTY_WIDTH
    + "s %" + PRICE_WIDTH + "." + PRICISION_FLOAT_WIDHT + "f\n"; //打印标题
    public void printTitle(){
    /*
    * 含义: 格式化字符串串以%开头
    * -: 表示左对齐
    * 15: 15表示宽度
    * s:表示数据的类型是String
    * .2f:表示浮点数保留的小数位数
    * .15s:表示字符串的长度最多15个字符
    */
    f.format(TITLE_FORMAT, "Item", "Qty", "Price");
    f.format(TITLE_FORMAT, "----", "---", "-----");
    } //正文的内容
    public void print(String name, int qty, double price){
    f.format(PRICE_FORMAT, name, qty, price);
    total += price;
    } //总价
    public void printTotal(){
    f.format(TOTAL_FORMAT, "Tax", "", total*0.06);
    f.format(TITLE_FORMAT, "", "", "-----");
    f.format(TOTAL_FORMAT, "Total", "", total*1.06);
    } public static void main(String[] args) {
    Receipt receipt = new Receipt();
    receipt.printTitle();
    receipt.print("Jack`s Magic Beans", , 4.25);
    receipt.print("Princess Peas", , 5.1);
    receipt.print("Three Bears Porridge", , 14.29);
    receipt.printTotal();
    } }

    运行结果:

    Item              Qty      Price
    ---- --- -----
    Jack`s Magic Be 4.25
    Princess Peas 5.10
    Three Bears Por 14.29
    Tax 1.42
    -----
    Total 25.06
  5. 第五题
    package net.mindview.strings;
    
    import java.util.Formatter;
    
    public class Receipt {
    private double total = ;
    private Formatter f = new Formatter(System.out);
    public final int ITEM_WIDTH = ;
    public final int QTY_WIDTH = ;
    public final int PRICE_WIDTH = ;
    public final int PRICISION_FLOAT_WIDHT = ;
    public final int PRICISION_String_WIDHT = ;
    public final String TITLE_FORMAT = "%-" + ITEM_WIDTH + "s %" + QTY_WIDTH
    + "s %" + PRICE_WIDTH + "s\n";
    public final String PRICE_FORMAT = "%-" + ITEM_WIDTH + "."
    + PRICISION_String_WIDHT + "s %" + QTY_WIDTH + "d %" + PRICE_WIDTH
    + "." + PRICISION_FLOAT_WIDHT + "f\n";
    public final String TOTAL_FORMAT = "%-" + ITEM_WIDTH + "s %" + QTY_WIDTH
    + "s %" + PRICE_WIDTH + "." + PRICISION_FLOAT_WIDHT + "f\n"; //打印标题
    public void printTitle(){
    /*
    * 含义: 格式化字符串串以%开头
    * -: 表示左对齐
    * 15: 15表示宽度
    * s:表示数据的类型是String
    * .2f:表示浮点数保留的小数位数
    * .15s:表示字符串的长度最多15个字符
    */
    f.format(TITLE_FORMAT, "Item", "Qty", "Price");
    f.format(TITLE_FORMAT, "----", "---", "-----");
    } //正文的内容
    public void print(String name, int qty, double price){
    f.format(PRICE_FORMAT, name, qty, price);
    total += price;
    } //总价
    public void printTotal(){
    f.format(TOTAL_FORMAT, "Tax", "", total*0.06);
    f.format(TITLE_FORMAT, "", "", "-----");
    f.format(TOTAL_FORMAT, "Total", "", total*1.06);
    } public static void main(String[] args) {
    Receipt receipt = new Receipt();
    receipt.printTitle();
    receipt.print("Jack`s Magic Beans", , 4.25);
    receipt.print("Princess Peas", , 5.1);
    receipt.print("Three Bears Porridge", , 14.29);
    receipt.printTotal();
    } }

    运行结果:

    Item              Qty      Price
    ---- --- -----
    Jack`s Magic Be 4.25
    Princess Peas 5.10
    Three Bears Por 14.29
    Tax 1.42
    -----
    Total 25.06
  6. afd
  7. 第七题:
    package net.mindview.strings.test7;
    
    public class Test7 {
    
        public static void main(String[] args) {
    //两种写法都可以
    String regex = "^[A-Z].*\\.$";
    String regex1 = "\\p{Upper}.*\\.$";
    String str = "D.";
    String str1 = "Dfasdfasfasfdasfdasfasfasdf.";
    String str2 = "Dfasdfasfasfdasfdasfasfasdf.E";
    System.out.println(str.matches(regex));
    System.out.println(str1.matches(regex));
    System.out.println(str2.matches(regex));
    System.out.println(str.matches(regex1));
    System.out.println(str1.matches(regex1));
    System.out.println(str2.matches(regex1));
    }
    }

    运行结果:

    true
    true
    false
    true
    true
    false
  8. 第八题
    package net.mindview.strings;
    
    import java.util.Arrays;
    
    public class Splitting {
    
        public static String knights = "Then, when you have found the shrubbery, you must cut down the mightiest tree in the forest... with... a herring!";
    
        public static void split(String regex){
    System.out.println(Arrays.toString(knights.split(regex)));
    }
    public static void main(String[] args) {
    //表示的时按照空格分割字符串
    //运行结果:[Then,, when, you, have, found, the, shrubbery,, you, must, cut, down, the, mightiest, tree, in, the, forest..., with..., a, herring!]
    split(" "); //表示按照非单次字符分割字符串--这里的非单次字符是空格和,
    //运行结果:[Then, when, you, have, found, the, shrubbery, you, must, cut, down, the, mightiest, tree, in, the, forest, with, a, herring]
    split("\\W+");
    //这个表示:费单次字符之前带n的地方进行分割字符串 这里的分割符是n空格和n,
    //运行结果:[The, whe, you have found the shrubbery, you must cut dow, the mightiest tree i, the forest... with... a herring!]
    split("n\\W+");
    } }
    package net.mindview.strings.test8;
    
    import net.mindview.strings.Splitting;
    
    public class Test8 {
    
        public static void main(String[] args) {
    String regex = "the|you";
    Splitting.split(regex);
    }
    }
  9. 第九题
    package net.mindview.strings.test9;
    
    import net.mindview.strings.Splitting;
    
    public class Test9 {
    public static void main(String[] args) {
    String regex = "A|E|I|O|U|a|e|i|o|u";
    //通过嵌入式标志表达式 (?i) 也可以启用不区分大小写的匹配。
    String regex1 = "(?i)a|e|i|o|u";
    //[abc] 表示a或b或c
    String regex2 = "(?i)[aeiou]";
    System.out.println(Splitting.knights.replaceAll(regex, "_"));
    System.out.println(Splitting.knights.replaceAll(regex1, "_"));
    System.out.println(Splitting.knights.replaceAll(regex2, "_"));
    }
    }
  10. 第十题
    package net.mindview.strings.test10;
    
    import java.util.regex.Matcher;
    import java.util.regex.Pattern; public class Test10 {
    public static void main(String[] args) {
    String str = "Java now has regular expressions"; for(String arg: args){
    Pattern p = Pattern.compile(arg);
    Matcher m = p.matcher(str);
    while(m.find()){
    System.out.println("Match \"" + m.group() +"\" at positions " + m.start() + "-" + (m.end()-) );
    }
    System.out.println("\n");
    } }
    }

    输入参数:

    ^Java
    \Breg.*
    n.w\s+h(a|i)s
    s?
    s*
    s+
    s{}
    s{}.
    s{,}

    输出结果

    Match "Java" at positions -
    
    Match "now has" at positions -
    
    Match "" at positions --
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "s" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "s" at positions -
    Match "s" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "s" at positions -
    Match "" at positions - Match "s" at positions -
    Match "ss" at positions -
    Match "s" at positions - Match "s " at positions -
    Match "ss" at positions - Match "" at positions --
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "s" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "ss" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "" at positions -
    Match "s" at positions -
    Match "" at positions -
  11. 第十一题
    package net.mindview.strings.test11;
    
    import java.util.regex.Matcher;
    import java.util.regex.Pattern; public class Test11 {
    public static void main(String[] args) {
    Pattern p = Pattern.compile("(?i)((^[aeiou])|(\\s+[aeiou]))\\w+?[aeiou]\\b");
    Matcher m = p.matcher("Arline ate eight apples and " +
    "one orange while Anita hadn't any"); while(m.find()){
    System.out.println("Match \"" + m.group() +
    "\" at positions " + m.start() + "-" +
    (m.end() - ));
    }
    }
    }

    运行结果:

    Match "Arline" at positions -
    Match " ate" at positions -
    Match " one" at positions -
    Match " orange" at positions -
    Match " Anita" at positions -
  12. sfa
  13. f
  14. a
  15. fda
  16. sdf
  17. af
  18. a
  19. fd
  20. af
  21. as
  22. fd
  23. asfd
  24. af
  25. da
  26. f
  27. df
  28. as
  29. fa
  30. sf
  31. asf
  32. a
  33. sf
  34. af
  35. asf

java编程思想第四版第十三章字符串 习题的更多相关文章

  1. java编程思想第四版第十三章字符串 总结

    1. String和StringBulider的使用 通过书中介绍, 我们得知如下结论: 当使用+连接符将字符串进行拼接的时候, 编译器会进行自动优化为使用StringBuilder连接字符串. 当在 ...

  2. java编程思想第四版第三章要点习题

    使用"简短的" 和正常的 打印语句来编写一个程序 package net.mindview.util; public class Print { /** * 不带有回车 * @pa ...

  3. java编程思想第四版第十一章习题

    第一题 package net.mindview.holding.test1; import java.util.ArrayList; import java.util.List; /** * 沙鼠 ...

  4. Java编程思想第四版*第七章*个人练习

    欢迎加群:239063848 成团的笔记:该组仅用于技术共享和交流,问题和答案公布 潘基聊天.禁止广告.禁止招聘-- 练习1:(2)创建一个简单的类.第二个类中,将一个引用定义为第一个类的对象.运用惰 ...

  5. java编程思想第四版第六章习题

    (略) (略) 创建两个包:debug和debugoff,他们都包含一个相同的类,该类有一个debug()方法,第一个版本显示发送给控制台的String参数,而第二版本什么也不做,使用静态import ...

  6. java编程思想第四版第六章总结

    1. 代码重构 为什么f要代码重构 第一次代码不一定是完美的, 总会发现更优雅的写法. 代码重构需要考虑的问题 类库的修改不会破坏客户端程序员的代码. 源程序方便扩展和优化 2. 包 创建一个独一无二 ...

  7. java编程思想第四版第五章习题

    创建一个类, 它包含一个未初始化的String引用.验证该引用被Java初始化成了null package net.mindview.initialization; public class Test ...

  8. java编程思想 第四版 第六章 个人练习

    欢迎加群:239063848 进群须知:本群仅用于技术分享与交流.问题公布与解答 禁止闲聊.非诚勿扰 练习1:(1)在某个包中创建一个类,在这个类所处的包的外部创建该类的一个实例. import mi ...

  9. java编程思想第四版第十一章总结

    1. 容器类被分为两类:Collection和Map Collection是一个接口:包括: List接口: ArrayList:按照被插入顺序保存元素, 查询快, 增删改慢 LinkedList:按 ...

随机推荐

  1. CVE-2019-0708(非蓝屏poc)远程桌面代码执行漏洞复现

    玩了几天 刚回成都  玩电脑复现一下~ 内核漏洞原理暂时 没看懂 别问 ,问就是不懂 0x01 复现环境和Exp准备 漏洞影响范围 Windows 7 Windows Server 2008 R2 W ...

  2. POJ 3020 Antenna Placement(二分图 匈牙利算法)

    题目网址:  http://poj.org/problem?id=3020 题意: 用椭圆形去覆盖给出所有环(即图上的小圆点),有两种类型的椭圆形,左右朝向和上下朝向的,一个椭圆形最多可以覆盖相邻的两 ...

  3. POJ 1753 Flip Game(状态压缩+BFS)

    题目网址:http://poj.org/problem?id=1753 题目: Flip Game Description Flip game is played on a rectangular 4 ...

  4. 查看java内存情况的几个常用命令

    java 命令简单查看jvm内存使用状况 jinfo:可以输出并修改运行时的java 进程的opts. jps:与unix上的ps类似,用来显示本地的java进程,可以查看本地运行着几个java程序, ...

  5. vue 自定义侧边栏 递归无限子级菜单

    有很多网站会涉及到导航栏,我自己在开发中用的是element导航组件,并且自定义事件,给大家分享一下. 1.使用递归方法,无限循环子级菜单. 2.使用组件封装,维护方便. 3.使用index作为路由跳 ...

  6. Linux常用命令-不定时记录

    文件移动命令 命令格式:mv [-fiv] source destination 参数说明:-f:force,强制直接移动而不询问-i:若目标文件(destination)已经存在,就会询问是否覆盖- ...

  7. PowerBI开发 第十五篇:Power BI的行级安全

    Power BI支持行级安全(Row-Level Security,RLS)的权限控制,用于限制用户对Dashboard.报表和DataSet的访问.用户浏览的报表是相同的,但是看到的数据却是不同的. ...

  8. call方法和apply方法

    1.call 语法 call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 参数 thisObj  可选项.将被用作当前对象的对象. arg1,arg2, , argN  ...

  9. (四)适配器Adapter

    只对简单应用进行描述.适配器与ListView配合使用可以快速生成item,效果如下例所示 一.简单模式 方式一 xml <ListView android:id="@+id/lv_t ...

  10. 游图邦YOTUBANG是如何搭建生态系统的?

    现在的我们最关心的一个问题就是任何一个行业,如果没有办法很好的落地,就算描绘的非常美好,那也只是空中楼阁.昙花一现而已,它无法实现长久的一个发展.互联网时代呢,就是一个流量为王的一个时代,谁拥有庞大的 ...