
正文
Java包含关系代码 java语言的关系表达式的运算结果是什么类型
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java求两个圆关系的代码,,求完整的,正确的源代码,谢谢!!
public class Cycle {
private double x = 0;//圆心横坐标
private double y = 0;//圆心纵坐标
private double r = 0;//圆心半径
public static void main(String[] args) {
String relation = "";
Cycle c = new Cycle(0,0,1);
//相交 外切 内切 相离
Cycle c_xiangJiao = new Cycle(3,4,5);
Cycle c_waiQie = new Cycle(3,4,4);
Cycle c_neiQie = new Cycle(3,4,6);
Cycle c_xiangLi = new Cycle(3,4,2);
relation = c.relationWithOtherCycle(c_xiangJiao);
System.out.println("c c_xiangJiao relationShip :"+relation);
relation = c.relationWithOtherCycle(c_xiangLi);
System.out.println("c c_xiangLi relationShip :"+relation);
relation = c.relationWithOtherCycle(c_neiQie);
System.out.println("c c_neiQie relationShip :"+relation);
relation = c.relationWithOtherCycle(c_waiQie);
System.out.println("c c_waiQie relationShip :"+relation);
}
public Cycle(double x, double y, double r) {
this.r = r;
this.x = x;
this.y = y;
}
public Cycle() {
}
public String relationWithOtherCycle(Cycle c){
String relation = ""; //相交 外切 内切 相离
double length = 0;// (x-x1)*(x-x1)+(y-y1)*(y-y1) 开平方
length = Math.sqrt((this.x-c.getX())*(this.x-c.getX())+(this.y-c.getY())*(this.y-c.getY()));
//System.out.println("length : "+length);
if(length(this.r+c.getR())){
relation = "相离";
}else if (length==(this.r+c.getR())){
relation = "外切";
}else if (length==Math.abs(this.r-c.getR())){
relation = "内切";
}else if (lengthMath.abs(this.r+c.getR())lengthMath.abs(this.r-c.getR())){
relation = "相交";
}
return relation;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
}
//把测试程序写在CycleJava包含关系代码的main方法里Java包含关系代码了
相关问答
Q1: 怎么根据JAVA中的代码画类之间的关系图
你说的是内存图把这个主要是自己脑海里有思路第一步做什么第二步做什么。然后就按照步骤来画。
Q2: Java中怎么比较输入的数组是否被已知数组包含
图片代码看不清, 我写了一个完整版的,你可以参考. 删除注释后,代码很短
public class AryDemo {
public static void main(String[] args) {
int[] ary1 = { 0, 8, 1, 0, 6 };
int[] ary2 = { 1, 6, 8 };
int[] ary3 = { 5, 2, 8 };
int[] ary4 = { 6, 6 };
int[] ary5 = { 0, 8, 1, 0, 1, 3, 6 };
System.out.println(isContent(ary1, ary2));// 包含
System.out.println(isContent(ary1, ary3));// 不包含,数组一没有元素5和2
System.out.println(isContent(ary1, ary4));// 不包含,数组一只有1个6 ,数组四有2个6
System.out.println(isContent(ary1, ary5));// 不包含,数组五长度比数组一还要长
if (isContent(ary5, ary1)) {
System.out.println("成功: ary5包含ary1");
} else {
System.out.println("Sorry: ary5不包含ary1");
}
}
//方法作用: 查找数组A是否包含数组B
//方法参数 两个int数组
//方法返回值 boolean类型 true代表包含 false代表不包含
public static boolean isContent(int[] aryA, int[] aryB) {
// 为空,或者A数组长度小于B数组返回false
if (aryA == null || aryB == null || aryA.length aryB.length) {
return false;
}
boolean[] flags = new boolean[aryA.length];// 用于标记A数组的元素是否被使用
int findTimes = 0;// 相同元素的个数
for (int i = 0; i aryB.length; i++) {
for (int j = 0; j aryA.length; j++) {
if (aryB[i] == aryA[j] !flags[j]) {// 如果aryA[j]的元素没有使用过,并且和aryB[i]相同
flags[j] = true; // 标记为已经使用了
findTimes++; // 相同元素+1
break;// 跳出本层循环,不再继续找了
}
}
}
return findTimes == aryB.length;// 返回元素个数和相同元素个数是否一致
}
}
测试结果
true
false
false
false
成功: ary5包含ary1
Q3: JAVA:编写一个动物的继承关系代码.
class animal{
public void walk(){
System.ou.println("用脚走哩!");
}
}
class wolf{
public void eat(){
System.out.println("我吃肉!");
}
}
class sleep{
public void eat(){
System.out.println("我吃草“);
}
}
Q4: Java课程设计源代码 家族亲属关系查询系统
public class Beetle extends Insect {
private int k = printInit("Beetle.k initialized");
public Beetle(){
System.out.println("k = " +k);
System.out.println("j = " + j);
}
private static int x2 = printInit("static Beetle.x2 initialized");
public static void main(String[] args){
System.out.println("Beetle constructor");
Beetle b = new Beetle();
}
}
关于Java包含关系代码和java语言的关系表达式的运算结果是什么类型的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







