当前位置:网站首页>Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
2022-04-23 03:05:00 【Roc-xb】
because 3²+4²=5², So it's called '3,4,5' Is the number of shares , seek n( Include n) Array of all Pythagorean numbers within .
such as :10 Within the Pythagorean array :['3,4,5','6,7,8']
Catalog
One 、 Topic analysis
We've all learned Pythagorean theorem , Know that Pythagorean theorem needs to meet a²+b²=c², We can split the two sides of the equation , First
Traverse once 1~n, Storage c Square result set of , And then through the double layer for Cycle calculation a²+b², Finally, judge a²+b² Are and in c In the square result set of , If in , Just explain ,a,b,c Satisfy the Pythagorean number relationship .
Two 、 Program code
package com;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
int n = 10;
List<Integer> zList = new ArrayList<>();
for (int i = 1; i <= n; i++) {
zList.add(i * i);
}
List<String> result = new ArrayList<>();
for (int x = 1; x < n; x++) {
for (int y = x; y < n; y++) {
int z = x * x + y * y;
if (zList.contains(z)) {
result.add(String.format("'%d,%d,%d'", x, y, (int) Math.sqrt(z)));
}
}
}
System.out.println(result);
}
}
3、 ... and 、 Running results
版权声明
本文为[Roc-xb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230302132059.html
边栏推荐
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
- AC & A2C & A3C
- 最通俗易懂的依赖注入之服务容器与作用域
- 【鉴权/授权】自定义一个身份认证Handler
- Introduction and use of openfeign component
- MYSQL05_ Ordr by sorting, limit grouping, group by grouping
- 全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
- Laravel8- use JWT
- 中后二叉建树
- C# 11 的这个新特性,我愿称之最强!
猜你喜欢
Recursion - outputs continuously increasing numbers
Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
Encapsulate components such as pull-down menu based on ele
tf. keras. layers. Conv? D function
Laravel8- use JWT
Introduction to ACM [inclusion exclusion theorem]
AspNetCore配置多环境log4net配置文件
Deep q-network (dqn)
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
Detailed log display of openfeign call
随机推荐
Redis data server / database / cache (2022)
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
Traversée de l'arbre L2 - 006
微软是如何解决 PC 端程序多开问题的——内部实现
Simple example of using redis in PHP
Distributed system services
LNMP MySQL allows remote access
Niuke white moon race 6 [solution]
Blazor University (11)组件 — 替换子组件的属性
How to write the expected salary on your resume to double your salary during the interview?
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
Openfeign timeout setting
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
Load view Caton
Response processing of openfeign
TP5 where query one field is not equal to multiple values
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
Judge whether there is a leap year in the given year
c#语法糖模式匹配【switch 表达式】