PTA基础编程题目集 7-21 求特殊方程的正整数解(Java实现)
程序员文章站
2022-06-09 21:25:24
...
题解
题解
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int N = in.nextInt();
boolean t = true;
int x = 1;
int y = 1;
for(x=1;x<=N;x++)//从一开始 一个个尝试
for(y=1;y<=N;y++)
{
if(x*x+y*y==N)
if(x<=y)//满足x<=y
{
t = false ;//由此来确定有解
System.out.print(x+" "+y);
System.out.print("\n");
}
}
if(t)
System.out.print("No Solution");
}
}
下一篇: 手把手带你走进Go语言之语法基础解析