| |

VerySource

 Forgot password?
 Register
Search
View: 692|Reply: 3

Help ~~~~

[Copy link]

2

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 20:30:01
| Show all posts |Read mode
import java.util. *;
public class youxi24 {// 24 games

public static void main (String [] args)
{
Ranch
int A [] = new int [13]; // 4 cards defined
int B [] = new int [13];
int C [] = new int [13];
int D [] = new int [13];
Random a = new Random ();
Random b = new Random ();
Random c = new Random ();
Random d = new Random ();
for (int j = 0; j <5; j ++) {// Draw 5 times
for (int i = 0; i <13; i ++) {
A [i] = Math.abs (a.nextInt ()% 12) +1;
B [i] = Math.abs (a.nextInt ()% 12) +1;
C [i] = Math.abs (a.nextInt ()% 12) +1;
D [i] = Math.abs (a.nextInt ()% 12) +1;
Ranch
if ((A [i] + B [i] -C [i]) * D [i] == 24) {
System.out.print ("(" + A [i] + "+" + B [i] + "-" + C [i] + ")" + "*" + D [i] + "= 24" );
System.out.println ();
}
}
}}

I do n’t know what the problem is, but I want to smoke 5 times
Each time the result is displayed, it is either 1 or 2, 3, 4, 6 times, or 1 time.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-4 02:00:01
| Show all posts
It was drawn 5 times, but in these 5 times, we still need to judge whether it meets the requirements. Only those that meet the requirements are output. If you output 1, 2 times, the remaining times do not meet the requirements.
What do you mean?
Reply

Use magic Report

2

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-4 10:54:01
| Show all posts
5 different results
no more, no less
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-7 06:12:01
| Show all posts
According to your requirements, your loop has a problem, modify it as follows:
import java.util. *;
public class youxi24 {// 24 games

public static void main (String [] args)
{
int j = 1;
int A [] = new int [13]; // 4 cards defined
int B [] = new int [13];
int C [] = new int [13];
int D [] = new int [13];
Random a = new Random ();
Random b = new Random ();
Random c = new Random ();
Random d = new Random ();
while (j <= 5) {// pump 5 times
for (int i = 0; i <13; i ++) {
A [i] = Math.abs (a.nextInt ()% 12) +1;
B [i] = Math.abs (a.nextInt ()% 12) +1;
C [i] = Math.abs (a.nextInt ()% 12) +1;
D [i] = Math.abs (a.nextInt ()% 12) +1;
Ranch
if ((A [i] + B [i] -C [i]) * D [i] == 24) {
System.out.print ("(" + A [i] + "+" + B [i] + "-" + C [i] + ")" + "*" + D [i] + "= 24" );
System.out.println ();
j ++;
}
}
}
}}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list