Fifth session Waterloo Cup Java Program C Group final question age coincidence

Source: Internet
Author: User

Title: Age Coincidence

Xiao Ming and his cousin go to the movies, some people ask their age. Xiao Ming said: This year is our lucky year ah. The four digits of my year of birth add up to just my age. Cousin's is also so. It is known that this year is 2014, and Xiao Ming refers to the age of years.

Please infer and fill out the year of Xiaoming's birth.

This is a 4-bit integer, please submit the answer through the browser, do not fill in any superfluous content (for example, his cousin's year of birth, or their age, etc.)

public class Main141 {public

	static void Main (string[] args) {
		int m = 2014;
		for (int i=1900;i<2014;i++) {
				int n = m-i;
				int t = i;
				int c = 0;
				while (t>0) {
					c + = t%10;
					t/=10;
				}
				if (c==n) {
					System.out.println (i);
				}
		}
	}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.