| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 516 人关注过本帖
标题:java初学,谁给看一下为什么不对啊,另外此类该如何使用Junit测试
只看楼主 加入收藏
伤城11
Rank: 1
等 级:新手上路
帖 子:6
专家分:5
注 册:2013-3-18
结帖率:0
收藏
已结贴  问题点数:5 回复次数:5 
java初学,谁给看一下为什么不对啊,另外此类该如何使用Junit测试
package com.li.test;

class Math
{
    private int no1;
    private int no2;
    private int no3=0;
    public void Sum()
    {
        no3=this.getNo1()+this.getNo2();
        System.out.println("Sum "+this.getNo1()+" + "+this.getNo2()+" = "+no3);
    }
    public void Sub()
    {
        no3=this.getNo1()-this.getNo2();
        System.out.println("Sub "+this.getNo1()+" + "+this.getNo2()+" = "+no3);
    }
    public void Mul()
    {
        no3=this.getNo1()*this.getNo2();
        System.out.println("Mul "+this.getNo1()+" + "+this.getNo2()+" = "+no3);
    }
    public void Div()
    {
        if (this.getNo2()!=0)
        no3=this.getNo1()/this.getNo2();
        System.out.println("Div "+this.getNo1()+" + "+this.getNo2()+" = "+no3);
    }
    public void setNo1(int a)
    {
        no1=a;
    }
    public void setNo2(int b)
    {
        no2=b;
    }
    public int getNo1()
    {
        return no1;
    }
    public int getNo2()
    {
        return no2;
    }
}
public class Add {
    public void main(String args[]){
    //    int a=0,b=0;
    //    System.in(a,b);
        Math math=new Math();
        math.setNo1(10);
        math.setNo2(5);
        math.Sum();
        math.Sub();
        math.Mul();
        math.Div();
    }
}
搜索更多相关主题的帖子: void java private package public 
2013-05-17 13:51
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
收藏
得分:3 
同学,我想说,你还是细心点吧,看看下面给色的:
package com.chinasoft.ti;

class Math
{
    private int no1;
    private int no2;
    private int no3=0;
    public void Sum()
    {
        no3=this.getNo1()+this.getNo2();
        System.out.println("Sum "+this.getNo1()+" + "+this.getNo2()+" = "+no3);
    }
    public void Sub()
    {
        no3=this.getNo1()-this.getNo2();
        System.out.println("Sub "+this.getNo1()+" - "+this.getNo2()+" = "+no3);
    }
    public void Mul()
    {
        no3=this.getNo1()*this.getNo2();
        
        System.out.println("Mul "+this.getNo1()+" * "+this.getNo2()+" = "+no3);
    }
    public void Div()
    {
        if (this.getNo2()!=0)
        no3=this.getNo1()/this.getNo2();
        System.out.println("Div "+this.getNo1()+" / "+this.getNo2()+" = "+no3);
    }
    public void setNo1(int a)
    {
        no1=a;
    }
    public void setNo2(int b)
    {
        no2=b;
    }
    public int getNo1()
    {
        return no1;
    }
    public int getNo2()
    {
        return no2;
    }
}
public class BBC {
    public static void main(String args[]){
    //    int a=0,b=0;
    //    System.in(a,b);
        Math math=new Math();
        math.setNo1(10);
        math.setNo2(5);
        math.Sum();
        math.Sub();
        math.Mul();
        math.Div();
    }
}

旨在提高编程水平,学有所用,学有所成,学有所为。
2013-05-17 15:45
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
收藏
得分:0 
输出的加减乘除没改,还有主函数没有STATIC

旨在提高编程水平,学有所用,学有所成,学有所为。
2013-05-17 15:46
神奈创
Rank: 3Rank: 3
等 级:论坛游侠
威 望:3
帖 子:67
专家分:191
注 册:2013-3-31
收藏
得分:3 
好牛逼啊,初学就能打这么多的代码了
2013-05-20 19:06
快速回复:java初学,谁给看一下为什么不对啊,另外此类该如何使用Junit测试
数据加载中...
 
   



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

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