• java 接口练习题6


    定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)。要求如下:

    1)可以生成具有特定坐标的点对象。

    2)提供可以设置三个坐标的方法。

    3)提供可以计算该“点”距原点距离平方的方法。

    4)编写主类程序验证。

    public class Point {
        private int a,b,c;
        Point (int a,int b,int c)
        {
            this.a=a;
            this.b=b;
            this.c=c;
        }
        public int getA() {
            return a;
        }
        public void setA(int a) {
            this.a = a;
        }
        public int getB() {
            return b;
        }
        public void setB(int b) {
            this.b = b;
        }
        public int getC() {
            return c;
        }
        public void setC(int c) {
            this.c = c;
        }
        public void Juli()
        {
            System.out.println("坐标"+a+","+b+","+c+"距离原点的距离的平方="+(a*a+b*b+c*c));
        }
        public static void main(String[] args) {
            Point p=new Point(2,2,2);
            p.Juli();
            p.setA(3);
            p.setB(5);
            p.setC(9);
            p.Juli();
        }

  • 相关阅读:
    [ARC117F]Gateau
    [ARC117D]Miracle Tree
    [loj3504]支配
    [gym102511K]Traffic Blights
    [loj3501]图函数
    [loj3503]滚榜
    [loj3500]矩阵游戏
    [loj2135]幻想乡战略游戏
    [cf720D]Slalom
    [cf1349E]Slime and Hats
  • 原文地址:https://www.cnblogs.com/jskbk/p/5531951.html
Copyright © 2020-2023  润新知