标题:程序加上空格和不加空格运行结果不一样
取消只看楼主
七小袋
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2015-11-20
结帖率:83.33%
已结贴  问题点数:20 回复次数:0 
程序加上空格和不加空格运行结果不一样
程序第六行在教育教学后面加空格结果为
全部图书:
    1.郁达夫随笔:伤感行旅    郁达夫    北京大学出版社    38.0
    2.教育教学              李晓燕     高等教育出版社    23.9
    3.普通化学原理与应用    比德勤    高等教育出版社    89.0
    4.机关工会工作指南    郭红梅    中国工人出版社    36.0
不加空格结果为
全部图书:
    1.郁达夫随笔:伤感行旅    郁达夫    北京大学出版社    38.0
    2.教育教学     李晓燕     高等教育出版社    23.9
    3.普通化学原理与应用    比德勤    高等教育出版社    89.0
    4.机关工会工作指南    郭红梅    中国工人出版社    36.0
求解为何教育教学作者显示不对齐,求解释下71至89行程序意思
public class lianxi16 {
    private Book[] booklist;
    lianxi16(){
        Book[]booklist={
                new Book("郁达夫随笔:伤感行旅","郁达夫","北京大学出版社",38.0f),//5行
                new Book("教育教学          ","李晓燕 ","高等教育出版社",23.9f),
                new Book("普通化学原理与应用","比德勤","高等教育出版社",89.0f),
                new Book("机关工会工作指南","郭红梅","中国工人出版社",36.0f)
        };
        this.booklist =booklist;
    }
    lianxi16(Book...book){
        booklist=book;
    }
    void getbookinfo(){
        System.out .println("全部图书:");
        for(int i=0;i<booklist.length ;i++){
            System.out .println("\t"+(i+1)+"."+booklist[i].title +
                                "\t"+booklist[i].author +
                                "\t"+booklist[i].publisher+
                                "\t"+booklist[i].price);
        }
    }
    void getbookinfo(float price){
        System.out .println("价格为“"+price+"”的图书:");
        int m=1;
        for(int i=0;i<booklist.length ;i++){
            if(booklist[i].price==price){
                System.out .println("\t"+m+"."+booklist[i].title +
                                    "\t"+booklist[i].author +
                                    "\t"+booklist[i].publisher);
                m++;
            }
        }
    }
    void getbookinfo(String publisher){
        System.out .println("出版社为“"+publisher+"”的图书:");
        int m=1;
        for(int i=1;i<booklist.length ;i++){
            if(booklist[i].publisher==publisher){
                System.out .println("\t"+m+"."+booklist[i].title +
                                    "\t"+booklist[i].author +
                                    "\t"+booklist[i].price);
                m++;
            }
        }
    }
    void getbookinfo(float price,String publisher){
        System.out .println("价格为“"+price+"”且出版社为“"+publisher+"”的图书:");
        int m=1;
        for(int i=0;i<booklist.length ;i++){
            if((booklist[i].price==price)&(booklist[i].publisher==publisher)){
                System.out .println("\t"+m+"."+booklist[i].title +
                                    "\t"+booklist[i].author );
                m++;
            }
        }
    }
    void getbookinfo(String publisher,float price){
        System.out .println("出版社为“"+publisher+"”且价格为“"+price+"”的图书:");
        int m=1;
        for(int i=0;i<booklist.length ;i++){
            if((booklist[i].publisher==publisher)&(booklist[i].price==price)){
                System.out .println("\t"+m+"."+booklist[i].title +
                                    "\t"+booklist[i].author );
                m++;
            }
        }
    }
    void getbookinfo(float...price){
        String s="";
        int m=1;
        for(float bookprice:price){
            s+=bookprice+" ";
        }
        System.out .println("价格为“"+s.trim()+"”的图书:");
        for(float bookprice:price){
            int i=0;
            while(i<booklist.length ){
                if(bookprice==booklist[i].price){
                    System.out .println("\t"+m+"."+booklist[i].title +
                                        "\t"+booklist[i].author +
                                        "\t"+booklist[i].publisher+
                                        "\t"+booklist[i].price);
                    m++;
                }
                i++;
            }
        }
        //void getbookinfo(float[]price){}
    }
    public static void main(String[]args){
        lianxi16 overloadtest=new lianxi16();
        overloadtest.getbookinfo();
        overloadtest.getbookinfo(36f);
        overloadtest.getbookinfo("高等教育出版社");
        overloadtest.getbookinfo(89f, "高等教育出版社");
        overloadtest.getbookinfo("北京大学出版社", 38f);
        overloadtest.getbookinfo(36f,23.9f,89f);
        overloadtest=null;
        overloadtest=new lianxi16(
                new Book("艺术批评学","陈汗青","北京大学出版社",28.0f),
                new Book("工程力学","范钦珊","高等教育出版社",71.0f)
                );
        overloadtest.getbookinfo();
    }

}
class Book{
    String title;
    String author;
    String publisher;
    float price;
    Book(String title,String author,String publisher,float price){
        this.title =title;
        this.author =author;
        this.publisher =publisher;
        this.price =price;
    }
}
搜索更多相关主题的帖子: 郁达夫 北京大学 高等教育 出版社 中国工人 
2015-11-27 17:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-459662-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.115908 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved