PAT试题 自守数(Java编写)
Posted Goldexperience
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT试题 自守数(Java编写)相关的知识,希望对你有一定的参考价值。
import java.util.Scanner; public class selfConservation { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int M = scan.nextInt(); int K[] = new int[M]; for (int i = 0; i < M; i++) { K[i] = scan.nextInt(); } /*for(int i=0;i<K.length;i++) { System.out.println(K[i]); }*/ for (int i = 0; i < K.length; i++) { if (K[i] < 10) { int search=0; for (int N = 0; N < 10; N++) { if (K[i] * K[i] * N % 10 == K[i]) { System.out.println(N + " " + N * K[i] * K[i]); search=1; break; } } if (search==0){ System.out.println("No"); } } else if (K[i] < 100) { int search=0; for (int N = 0; N < 10; N++) { if (K[i] * K[i] * N % 100 == K[i]) { System.out.println(N + " " + N * K[i] * K[i]); search=1; break; } } if (search==0){ System.out.println("No"); } } else { int search=0; for (int N = 0; N < 10; N++) { if (K[i] * K[i] * N % 1000 == K[i]) { System.out.println(N + " " + N * K[i] * K[i]); search=1; break; } } if (search==0){ System.out.println("No"); } } } } }
以上是关于PAT试题 自守数(Java编写)的主要内容,如果未能解决你的问题,请参考以下文章