The Java Cycle Exercise 2

Source: Internet
Author: User

Practice 1:1 people very unlucky, accidentally smashed a woman's basket of eggs. Ask how many eggs are in the basket for compensation.
The woman said, she is not clear, only remember to take two each time one, each take 3 is left 2,
Take 5 each time Left 4, if each egg 1 yuan, ask you to help programming, calculate the minimum should pay how much money?
Requirements: With the Loop statement implementation, directly print out the results do not give points.

Package Com.cdp.project;public class Task1 {public static void main (string[] args) {//TODO auto-generated method stub//make Use the exhaustive method to one by one try to see if the condition can be met  boolean flag = true;   Initialize the number of eggs   int n = 1;   Meet the conditions on the sleepover cycle Flag=false;  while (flag) {if (n 2 = = 1 & n% 3 = = 2 && n% 5 = 4) {flag = false;} Change the value of n n++;n++;} SYSTEM.OUT.PRINTLN ("deductible" + (n-1) + "block Money"); /** method Two: * int n = 1;  * while (true) {*  if (n 2 = = 1 & N 3 = = 2 && n% 5 = 4) {* BREAK;  *} *  n++;  *  } System.out.println ("compensable" + N + "block Money"); */}

Run

It should cost 29 bucks.

The Java Cycle Exercise 2

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.