MyException - 我的异常网
当前位置:我的异常网» J2SE » 看看哪里错了。

看看哪里错了。

www.MyException.Cn  网友分享于:2013-12-16  浏览:2次
看看错哪了。。。
public class Point{
  public double x;
  public double y;
public void show(){
  System.out.println("("+x+","+y+")");
}
public Point(double x1,double y1){
  x=x1;
  y=y1;
}
public static void main(String args[]){
  double a;
  double b;
  Point m=new Point(12.5,8);
  Point n=new Point(10,5);
  public void getMiddle(Point m,Point n){
  a=(m.x+n.x)/2;
  b=(m.y+n.y)/2;
  System.out.println("("+a+","+b+")");
  }
  }
}

------解决方案--------------------
Java code
public class Point{
      public double x;
      public double y;
    public void show(){
      System.out.println("("+x+","+y+")");
    }
    public Point(double x1,double y1){
      x=x1;
      y=y1;
    }
    public static void getMiddle(Point m,Point n){
          double a;
          double b;
          a=(m.x+n.x)/2;
          b=(m.y+n.y)/2;
          System.out.println("("+a+","+b+")");
          }
    public static void main(String args[]){
         Point m=new Point(12.5,8);
         Point n=new Point(10,5);
         getMiddle(m, n);
      
      }
    }

------解决方案--------------------
main函数里怎么又写了个方法
main函数不属于任何类
看看下面帮你改的
Java code

package com.yxk.test;

public  class Point{
      public double x;
      public double y;
      
    public void show(){
      System.out.println("("+x+","+y+")");
    }
    public Point(){}
    public Point(double x1,double y1){
      x=x1;
      y=y1;
    }
    public static class Test{
         public void getMiddle(Point m,Point n){
              double a;
              double b;
              a=(m.x+n.x)/2;
              b=(m.y+n.y)/2;
              System.out.println("("+a+","+b+")");
              }
    }

public static void main(String args[]){
     
      Point m=new Point(12.5,8);
      Point n=new Point(10,5);
      new Test().getMiddle(m, n);
      }
    
}

------解决方案--------------------
探讨
为什么方法不能在main方法里使用呢

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有