## Java process control exercises

Irving the procedural ape 2020-11-08 14:32:25
java process control exercises

The first question ： Suppose Xiao Ming has 100 Yuan , At this time, Xiao Ming needs change when he goes to the supermarket , The change provided by the supermarket is 1 Yuan in face value ,2 Yuan in face value ,5 Yuan in face value ,10 Yuan in face value ,20 Yuan in face value ,50 Yuan in face value , Ask Xiao Ming how many ways to exchange ？
The second question ： Suppose Xiao Ming has 100 Yuan , At this time, Xiao Ming goes to the supermarket to buy Coke , coke 3 A bottle for \$1 , The supermarket seller sells Xiao Ming a bottle of coke every time , It's more expensive than the original 2/3 The price of , Xiao Ming's bottles can be exchanged for half a coke for each bottle ( Only half a bottle can't be replaced ), How many bottles of coke can Xiao Ming buy in the supermarket ？
The third question ： Print pattern title ：

1. Print 7 The solid diamond of the row
2. Print 11 Solid trapezoid of rows
3. Print 13 Row solid isosceles right triangle
The fourth question ： Please 10 The sum of all multipliers within 1!+2!+3!+.....+10!=?
The fifth question ： The case of raw rabbit ： Suppose you have a pair of Rabbits , Not born in the first month , I don't give birth in the second month , In the third month, a couple of rabbits were born , Rabbits are born every third month , When the rabbit grows up to the third month, it gives birth to another pair of rabbits every month , If the rabbits don't die , ask 12 Months later, , How many pairs of rabbits do you have ？
The sixth question ： Give any one 10 Positive integers within bits , Determine the number of digits ？
The seventh question ： Factoring a positive integer into factors ,
The eighth question ： Given any two positive integers , Find their greatest common divisor and least common multiple .
The ninth question ： Please 1000 All the completions within . Complete = If a number is exactly equal to the sum of its factors , This number is called a perfect number 6 = 1 + 2 + 3 = 6
The tenth question ：

The first question is ：
Suppose Xiao Ming has 100 Yuan , At this time, Xiao Ming needs change when he goes to the supermarket , The change provided by the supermarket is 1 Yuan in face value ,2 Yuan in face value ,5 Yuan in face value ,10 Yuan in face value ,20 Yuan in face value ,50 Yuan in face value , Ask Xiao Ming how many ways to exchange ？
The answer is as follows ：

[plain] view plaincopy
1. int a1 = 0;
2. for (int i1 = 0;i1<=100;i1++){
3. for (int i2 = 0;i2<=50;i2++){
4. for (int i5=0;i5<=20;i5++){
5. for (int i10=0;i10<=10;i10++){
6. for (int i20=0;i20<=5;i20++){
7. for (int i50=0;i50<=2;i50++){
8. if (i1*1+i2*2+i5*5+i10*10+i20*20+i50*50==100){
9. a1++;
10. }
11. }
12. }
13. }
14. }
15. }
16. }
17. System.out.println(a1);

The second question ：
Suppose Xiao Ming has 100 Yuan , At this time, Xiao Ming goes to the supermarket to buy Coke , coke 3 A bottle for \$1 , The supermarket seller sells Xiao Ming a bottle of coke every time , It's more expensive than the original 2/3 The price of , Xiao Ming's bottles can be exchanged for half a coke for each bottle ( Only half a bottle can't be replaced ), How many bottles of coke can Xiao Ming buy in the supermarket ？
The answer is as follows ：

[plain] view plaincopy
1. double money2 = 100.0;
2. double kele2 =3.0;
3. double a2 = 3.0;
4. double b2 = 2.0;
5. double c2 = b2/a2;
6. int d2 = 0;
7. for (int i2 = 0;money2>kele2;i2++){
8. money2 = money2 - kele2;
9. kele2 =kele2 + kele2 * c2;
10. d2++;
11. if (d2%2==0){
12. d2++;
13. }
14. }
15. System.out.println(d2);

The third question ： Print pattern title ：

1. Print 7 The solid diamond of the row

2. Print 11 Solid trapezoid of rows
3. Print 13 Row solid isosceles right triangle
The answer is as follows ：[plain] view plaincopy
1. // The diamond
2. for(int i3=1;i3<=4;i3++){
3. for (int a3=1;a3<=4-i3;a3++){
4. System.out.print(" ");
5. }
6. for(int a3=1; a3<=(2*i3-1);a3++){
7. System.out.print("*");
8. }
9. System.out.println();
10. }
11. for(int i3=3;i3>=1;i3--){
12. for (int a3=1;a3<=4-i3;a3++){
13. System.out.print(" ");
14. }
15. for(int a3=1; a3<=(2*i3-1);a3++){
16. System.out.print("*");
17. }
18. System.out.println();
19. }// trapezoid
20. for (int i = 3;i<=13;i++){
21. for (int a=1;a<=13-i;a++){
22. System.out.print(" ");
23. }
24. for (int c=1;c<=(2*i-1);c++){
25. System.out.print("*");
26. }
27. System.out.println();
28. }
29. // right triangle
30. for (int i =1;i<=12;i++){
31. for (int i1=1;i1<=i;i1++){
32. if (i==i1||i1==1){
33. System.out.print(" "+"*");
34. }else{
35. System.out.print(" "+" "+" ");
36. }
37. }
38. System.out.println("");
39. }
40. System.out.println(" *  *  *  *  *  *  *  *  *  *  *  *  *");

The fourth question ：
Please 10 The sum of all multipliers within 1!+2!+3!+.....+10!=?
The answer is as follows ：
// Fourth question

[plain] view plaincopy
1. int a4 = 1;
2. int c4 = 0;
3. for (int i4 = 1; i4<=10;i4++){
4. for (int b4 =1;b4<=i4;b4++){
5. a4=a4*b4;
6. }
7. c4=c4+a4;
8. a4=1;
9. }
10. System.out.println(c4);

The fifth question ：
The case of raw rabbit ： Suppose you have a pair of Rabbits , Not born in the first month , I don't give birth in the second month , In the third month, a couple of rabbits were born , From the third month .........