import  java.io.*; 
public class TC {
double  x,y;
TC(double x,double y){
if(x<=5)
y=1-x*x;
else
y=x-5;

}
void show()
{ System.out.println(y);
}
    
    public static void main(String[] args) {
     double M;
     double N=0.0;
     System.out.println("input");
     BufferedReader in=new BufferedReader(new InputStreamReader(System.in);
     M=double .parseDouble(in.readLine());
     N=double .parseDouble(in.readLine());
     TC r=new TC(M,N);
        r.show();
    
    
    }
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zhangbin55661】截止到2008-07-13 10:28:38的历史汇总数据(不包括此帖):
    发帖的总数量:7                        发帖的总分数:140                      每贴平均分数:20                       
    回帖的总数量:3                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:4                        结贴的总分数:80                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:3                        未结的总分数:60                       
    结贴的百分比:57.14 %               结分的百分比:57.14 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主加油
      

  2.   

    double  x,y;
    TC(double x,double y){
    if(x <=5)
    y=1-x*x;
    else
    y=x-5;}
    注意构造方法里的x,y和field x,y没有什么关系。因为名字覆盖的问题。在构造方法中出现这种情况的时候用this来指明field x和 y。
    比如 this.x和 this.y,直接用的话是参数列表里的x和y
      

  3.   

    你的这段程序错的蛮多的,帮你改了.可以运行了.import  java.io.*; 
    public class TC { 
    double  x,y; 
    TC(double x,double y){ 
     this.x=x;
     this.y=y;} 
    void show() 
    {
    if(x <=5) 
    y=1-x*x; 
    else 
    y=x-5;
     System.out.println(y); 

        
        public static void main(String[] args) throws Exception{ 
        double M; 
        double N=0.0; 
        System.out.println("input"); 
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 
        M=new Double(in.readLine()).doubleValue(); 
        N=new Double(in.readLine()).doubleValue(); 
        TC r=new TC(M,N); 
            r.show(); 
        
        
        } 
      

  4.   

    double.parseDouble(in.readLine()); 
    double不是对象
      

  5.   

    import  java.io.*; 
    public class TC { 
    double  x,y; 
    TC(double x,double y){ 
     this.x=x;
     this.y=y;} 
    void show() 
    {
        if(x <=5) 
    y=1-x*x; 
    else 
    y=x-5;
         System.out.println(y); 

        
        public static void main(String[] args) throws Exception{ 
        double M; 
        double N=0.0; 
        System.out.println("input"); 
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 
        M=new Double(in.readLine()).doubleValue(); 
        N=new Double(in.readLine()).doubleValue(); 
        TC r=new TC(M,N); 
            r.show(); 
        
        
        } 

      

  6.   

    建议使用idea软件,这样他会帮你调试代码,错误就显示出来。这样你就知道哪里语法错了。。飘过,
      

  7.   

    三楼的仁兄能不能解释一下M=new Double(in.readLine()).doubleValue(); 中的语法啊。谢了。
      

  8.   

    三楼的兄弟double.parseDouble(in.readLine()); 不是将字符转为数字的吗?
      

  9.   

    import java.io.*;public class Tc {
    double x, y; Tc(double x, double y) {
    if (x <= 5)
    y = 1 - x * x;
    else
    y = x - 5; } void show() {
    System.out.println(y);
    } public static void main(String[] args) {
        double M;
        double N=0.0;
        System.out.println("input");
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        try {
    M=Double .parseDouble(in.readLine());
     N=Double .parseDouble(in.readLine());     Tc r=new Tc(M,N);
            r.show();
       
    } catch (NumberFormatException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
       
       
        }
    }
    可以了,不过你的程序只会打印0.0,,,
    构造方法里===>>this.y  
      

  10.   

    [code]
    import  java.io.*; public class TC { 
    double  x,y; 
    TC(double x,double y){ 
    if(x <=5) 
    this.y=1-x*x; 
    else 
    this.y=x-5; 

    void show() 
    {
    System.out.println(y); 

        
        public static void main(String[] args) throws Exception{ 
        double M; 
        double N=0.0; 
        System.out.println("input"); 
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 
        M=Double.parseDouble(in.readLine()); 
        N=Double.parseDouble(in.readLine()); 
        TC r=new TC(M,N); 
        r.show(); 
        } 

    [/code]
    错误1:这里的double应该是封装类d需要大写
    错误2:System.in后面查一个括号
    错误3:构造里面的y前应该有一个(this.),否则每次运行都是0.0
      

  11.   

    java code
    import  java.io.*; public class TC { 
    double  x,y; 
    TC(double x,double y){ 
    if(x <=5) 
    this.y=1-x*x; 
    else 
    this.y=x-5; 

    void show() 
    {
    System.out.println(y); 

        
        public static void main(String[] args) throws Exception{ 
        double M; 
        double N=0.0; 
        System.out.println("input"); 
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 
        M=Double.parseDouble(in.readLine()); 
        N=Double.parseDouble(in.readLine()); 
        TC r=new TC(M,N); 
        r.show(); 
        }