Title basic programming set positive integer 7-21 Solutions of special equations (15 minutes)

Here Insert Picture Description

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int x = 0, y = 0, N = 0, flag = 0;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		for (x = 1; x <= 100; x++) {
			for (y = x; y <= 100; y++) { // 关于y定义域--x<=y<=100 的处理
				if (x * x + y * y == N) {
					flag = 1;
					System.out.println(x + " " + y);
					break;
				}
			}
		}
		if (flag == 0) {
			System.out.println("No Solution");
		}
		sc.close();
	}

}
Published 287 original articles · won praise 117 · Views 8931

Guess you like

Origin blog.csdn.net/qq_44458489/article/details/105400093