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) #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++浮点有很多问题,谷歌尝试但它就像一个谜题.