Java实现 蓝桥杯VIP 算法提高 勾股数

算法提高 勾股数
时间限制:1.0s 内存限制:256.0MB
问题描述
  勾股数是一组三个自然数,a < b < c,以这三个数为三角形的三条边能够形成一个直角三角形
  输出所有a + b + c <= 1000的勾股数
  a小的先输出;a相同的,b小的先输出。
输出格式
  每行为一组勾股数,用空格隔开
样例输出
例如,结果的前三行应当是
3 4 5
5 12 13
6 8 10


public class 勾股数 {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for (int a = 3; a <=1000; a++) {
			for (int b =a+1; b < 1000; b++) {
				int c=(int) Math.sqrt(a*a+b*b);
					if(a<b&&b<c){
						if(a+b+c<=1000){
							if(a*a+b*b==c*c){
								System.out.println(a+" "+b+" "+c);
							}
						}
					
					
				}
			}
			}
		}

}

原文地址:https://www.cnblogs.com/a1439775520/p/12948400.html