stl02 发表于 2003-7-21 13:18

最初由 leotao 发布
instaniier...

richtig - Instanzierung!

ZICK 发表于 2003-7-21 13:25

搞定...

谢谢楼上诸位了

ZICK 发表于 2003-7-21 13:29

不好意思,能不能麻烦再看看下例

public class LineTest
{
        public static void main(String args[])
        {
           Line line = new Line(0,0,10,20);
           line.moveVertical(10);
           line.moveHorizontal(20);
                System.out.println(line.startPoint.toString() + "," + line.endPoint.toString());
        }
}

public class Line
{
   Point startPoint, endPoint;
   public Line(int x1, int y1, int x2, int y2)
   {
      startPoint = new Point (x1, y1);
      endPoint = new Point (x2,y2);
   }
   
   public Line()
   {
      this (0,0,0,0);
   }
   
   public void moveVertical(int distance)
   {
      startPoint.incrY(distance);
      endPoint.incrY(distance);
   }
   
   public void moveHorizontal(int distance)
   {
      startPoint.incrX(distance);
      endPoint.incrX(distance);
   }
}

public class Point
{
   private int x,y;
   
   public Point(int x,int y)
   {
      this.x = x;
      this.y = y;
   }
   
   public void incrX(int d)
   {
      x += d;
   }
   
   public void incrY(int d)
   {
      y += d;
   }
   
   public String toString()
   {
      return x + "/" + y;
   }
}

LineTest.java:12: class Line is public, should be declared in a file named Line.java
public class Line
       ^
LineTest.java:39: class Point is public, should be declared in a file named Point.java
public class Point
       ^
2 errors
Exit code: 1
There were errors

two steps 发表于 2003-7-21 13:59

那就把2个public 去了.

ZICK 发表于 2003-7-21 14:04

谢了!

具体这一句是什么意思啊?

public Point(int x,int y)
   {
      this.x = x;
      this.y = y;
   }

ZICK 发表于 2003-7-21 14:15

好像是个很常见的例子

public class SortDemo
{
        public static void main(String args[])
        {
                int[] arrayOfInts = { 32,87,3,589,12,1076,2000,8,622,127 };
               
                for (int i= arrayOfInts.length;--i>=0;)
                  { for (int j=0;j<i;j++)
                { if (arrayOfInts > arrayOfInts)
                     {int temp = arrayOfInts;
                              arrayOfInts = arrayOfInts;
                              arrayOfInts = temp;
                               }
                            }
                     }
                for (int i=0;i < arrayOfInts.length;i++)
                  { System.out.println(arrayOfInts + " ");
                  }
                System.out.println();       
        }
}

但是中间这一段没读懂...

if (arrayOfInts > arrayOfInts)
                     {int temp = arrayOfInts;
                              arrayOfInts = arrayOfInts;
                              arrayOfInts = temp;
                               }

two steps 发表于 2003-7-21 14:25

是class Point的konstruktor.
class Point
{
private int x,y;    这两个是class point 的 attribute

public Point(int x,int y)   // konstruktor注意, 一定是public .this是关键字
{
this.x = x;                  
this.y = y;
}

public void incrX(int d)   // 这以下就都是methode 了
{
x += d;
}

public void incrY(int d)
{
y += d;
}

public String toString()
{
return x + "/" + y;
}
}

two steps 发表于 2003-7-21 14:34

回第16贴.

程序好象bubblesort 吧.......8)   
if (arrayOfInts > arrayOfInts)
{int temp = arrayOfInts;
arrayOfInts = arrayOfInts;
arrayOfInts = temp;
}

如果Array中第j个元素大于它后边那个, 即第j+1个, 那么就将他们两个的位置交换.
比如87 大于 3 吧, 那执行完这5行后, 就成 3 在8 前边了.
全部运行完了应该是个从小排到大的folge

two steps 发表于 2003-7-21 14:44

检讨一下,我觉得我这个讲的不清楚.
public Point(int x,int y)
{
this.x = x;
this.y = y;
}

你也可以这么写.
public Point ( int a , int b )
{
x= a;
y= b;
}
这样是不是对于谁给谁附值清楚点了呢?:-)

ZICK 发表于 2003-7-21 14:44

懂了

谢谢 two steps 了...

今天到此为止了,呵呵...
页: 1 [2] 3
查看完整版本: [求助]刚开始学,一头雾水...