欧拉砖实现 Java 版本

huangapple 未分类评论44阅读模式
英文:

Euler Brick imlementation in Java

问题

你好,以下是翻译好的部分:

public class EulerBrick {

	private int a, b, c;
	private int d, e, f;
	private Random random;

	public EulerBrick(int a, int b, int c) {
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = (int) Math.sqrt((a * a) + (b * b));
		this.e = (int) Math.sqrt((a * a) + (c * c));
		this.f = (int) Math.sqrt((b * b) + (c * c));
		this.random = new Random();

		if (verify(a, b, c, random.nextInt())) {
			if (a % 3 != 0) {
				if (b % 3 != 0) return;
				if (c % 3 != 0) return;
			}
			if (a % 4 != 0) {
				if (b % 4 != 0) return;
				if (c % 4 != 0) return;
			}
			if (a % 11 != 0) {
				if (b % 11 != 0) {
					if (c % 11 != 0) return;
				}
			}
		} else return;

		printDimensions();
	}

	public boolean verify(double a, double b, double c, int k) {
		a *= k;
		b *= k;
		c *= k;

		if (a % 3 != 0) {
			if (b % 3 != 0) return false;
			if (c % 3 != 0) return false;
		}
		if (a % 4 != 0) {
			if (b % 4 != 0) return false;
			if (c % 4 != 0) return false;
		}
		if (a % 11 != 0) {
			if (b % 11 != 0) {
				if (c % 11 != 0) return false;
			}
		}
		return true;
	}

	public void printDimensions() {
		System.out.println("Side A: " + a + ", Side B: " + b + ", Side C: " + c + ", Side D: " + d + ", Side E: " + e + ", Side F: " + f);
	}

}
public class Main {

	public static void main(String[] args) throws InterruptedException {
		int i = 0, j = 0, k = 0;

		while (true) {
			new EulerBrick(i += 3, j += 4, k += 11);
			Thread.sleep(1000);
		}

//		EulerBrick brick = new EulerBrick(44, 117, 240);
	}

}

如果有其他需要翻译的部分,请随时告诉我。

英文:

Hello to all who are taking the time out of their day to attempt and help solve my problem. I am truly stuck for the first time in a while and would really appriciate some help. But enough exposition; here is the what I have implemented thus far:

public class EulerBrick {

	private int a, b, c;
	private int d, e, f;
	private Random random;

	public EulerBrick(int a, int b, int c) {
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = (int) Math.sqrt((a * a) + (b * b));
		this.e = (int) Math.sqrt((a * a) + (c * c));
		this.f = (int) Math.sqrt((b * b) + (c * c));
		this.random = new Random();

		if (verify(a, b, c, random.nextInt())) {
			if (a % 3 != 0) {
				if (b % 3 != 0) return;
				if (c % 3 != 0) return;
			}
			if (a % 4 != 0) {
				if (b % 4 != 0) return;
				if (c % 4 != 0) return;
			}
			if (a % 11 != 0) {
				if (b % 11 != 0) {
					if (c % 11 != 0) return;
				}
			}
		} else return;

		printDimensions();
	}

	public boolean verify(double a, double b, double c, int k) {
		a *= k;
		b *= k;
		c *= k;

		if (a % 3 != 0) {
			if (b % 3 != 0) return false;
			if (c % 3 != 0) return false;
		}
		if (a % 4 != 0) {
			if (b % 4 != 0) return false;
			if (c % 4 != 0) return false;
		}
		if (a % 11 != 0) {
			if (b % 11 != 0) {
				if (c % 11 != 0) return false;
			}
		}
		return true;
	}

	public void printDimensions() {
		System.out.println("Side A: " + a + ", Side B: " + b + ", Side C: " + c + ", Side D: " + d + ", Side E: " + e + ", Side F: " + f);
	}

}

And here is the main class I am using to test it:

public class Main {

	public static void main(String[] args) throws InterruptedException {
		int i = 0, j = 0, k = 0;

		while (true) {
			new EulerBrick(i += 3, j += 4, k += 11);
			Thread.sleep(1000);
		}

//		EulerBrick brick = new EulerBrick(44, 117, 240);
	}

}

Again any help would be greatly appreciated. Also this isn't for a course/class just an exercise that Ive stumped myself on.

huangapple
  • 本文由 发表于 2020年4月7日 04:07:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61068099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定