连续正整数的和

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));
		}

	}

}

posted @ 2020-04-13 15:40  西红柿里没有番茄  阅读(150)  评论(0编辑  收藏  举报