连续正整数的和

package _4_9_test;

import java.util.ArrayList;
import java.util.Scanner;

/*连续正整数的和
 * 
 * */
public class SeventyNight {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<Integer> arrayList = new ArrayList<>();
		int a, b;

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();

		int count;
		int result;
		for (int i = 1; i <= n / 2; i++) {
			result = 0;
			count = i;
			while (true) {
				result += count;
				if (result == n) {
					a = i;
					b = count;
					arrayList.add(a);
					arrayList.add(b);
					break;
				} else if (result > n) {
					break;
				}
				count++;
			}
		}

//		结果输出
		for (int i = 0; i < arrayList.size(); i += 2) {
			System.out.println(arrayList.get(i) + " " + arrayList.get(i + 1));
		}

	}

}

猜你喜欢

转载自www.cnblogs.com/lyd447113735/p/12691730.html