Blue Bridge Cup test questions basic exercises special palindrome number (java)

Blue Bridge Cup test questions basic exercises special palindrome number (java)


Problem Description
  123321 is a very special number that reads the same from the left as it reads from the right. Input a positive integer n, program to find all such five-digit and six-digit decimal numbers, satisfying that the sum of each digit is equal to n.
  
Input format
  Input a line, including a positive integer n.
  
Output
  format Output the integers that meet the conditions in ascending order, and each integer occupies one line.
  
Sample input
52

Sample output
899998
989989
998899

Data scale and convention
1<=n<=54.

import java.util.Scanner;

public class Main{
    
    

	public static void main(String[] args) {
    
    
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		for (int i = 10000; i <= 99999; i++) {
    
    
			String string=String.valueOf(i);
			int a=Integer.valueOf(string.substring(0, 1));
			int b=Integer.valueOf(string.substring(1, 2));
			int c=Integer.valueOf(string.substring(2, 3));
			int d=Integer.valueOf(string.substring(3, 4));
			int e=Integer.valueOf(string.substring(4, 5));
			if (a!=e||b!=d||(a+b+c+d+e!=n)) {
    
    
				continue;
			}
			System.out.println(""+a+b+c+d+e);
		}
		for (int i = 100000; i <=999999 ; i++) {
    
    
			String string=String.valueOf(i);
			int a=Integer.valueOf(string.substring(0, 1));
			int b=Integer.valueOf(string.substring(1, 2));
			int c=Integer.valueOf(string.substring(2, 3));
			int d=Integer.valueOf(string.substring(3, 4));
			int e=Integer.valueOf(string.substring(4, 5));
			int f=Integer.valueOf(string.substring(5, 6));
			if (a!=f||b!=e||c!=d||(a+b+c+d+e+f!=n)) {
    
    
				continue;
			}
			System.out.println(""+a+b+c+d+e+f);
		}
	}
}

Guess you like

Origin blog.csdn.net/qq_45451150/article/details/113723934