小编inh*_*ler的帖子

从其子类的实例访问超类的属性

class Person {
    public String name;
    String id;

    public Person() {
        System.out.println("Parent default");
        name = id = "";
    }

    public Person(String name, String id) {
        System.out.println("Parent parameter");
        this.name = name;
        this.id = id;
    }

    void show() {
        System.out.println(this.name + "\n" + this.id);
    }
}

class Student extends Person {

    Student() {}

    Student(String a, String b) {
        super(a, b);
    }
}

class Main {
    public static void main(String args[]) {
        Person p = new Person("A", "AA");
        Student s = new Student("b", …
Run Code Online (Sandbox Code Playgroud)

java inheritance super

1
推荐指数
1
解决办法
7658
查看次数

终止小数

#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
double a,b,res;

while(cin>>a>>b)
{
    res = a/b;

    if((res*b) == a)
        cout<<"Terminates"<<endl;
    else
        cout<<"Does not terminate"<<endl;
}

return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以,这是我的代码,看看a/b是否导致终止小数.一些输入正在生成正确的输出,如:

1/3:不会终止,

1/9:不终止,

1/7:不会终止,

22/7:不会终止,

1/2:终止.

除了应该显示的1/5 1/5 : Terminates,但是输出是:Does not terminates.

我知道C++浮点有很多问题,谷歌尝试但它就像一个谜题.

c++ floating-point precision

1
推荐指数
1
解决办法
412
查看次数

标签 统计

c++ ×1

floating-point ×1

inheritance ×1

java ×1

precision ×1

super ×1