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