It's been a month and a half since I started studying Java, and I have the task of creating a simple game.
The contents of the game are as follows.
・ 3 players
・ Roll the dice 3 times each and find the total value for each.
・ The person with the largest total value wins
I'm creating it using an array and random numbers, but I'm stumbling because I don't know how to write the code to find the total value.
I would appreciate it if you could teach me.
I look forward to working with you.
[1]: 5 3 1
9 ← The total value is not calculated, and it seems that the random number is output as it is.
[2]: 2 6 3
8 ← The total value is not calculated, and it seems that the random number is output as it is.
[3]: 5 2 6
5 ← The total value is not calculated, and it seems that the random number is output as it is.
package test;
public class SaikoroGames {
public static void main (String [] args) {
// Decide the number of players
int [] r = {1,2,3};
int sum = 0;
// Loop for the number of people
for (int j = 0;j
for (int i = 0;i
System.out.print (dice () + "");
sum = dice () + dice () + dice ();
}
}
System.out.println ();
System.out.print (sum);
System.out.println ();
}
}
// roll the dice
static int dice () {
return (int) (Math.random () * 6) + 1;
}
}
I googled how to find the total value using an array and random numbers, but it didn't work.
Supplementary information (FW/tool version, etc.)
Answer # 1

Answer # 2
The total value is not calculated, and it looks like the random number is output as it is.
You can only see it (if you put it out as it is, you won't get "8" or "9"). The total value of the random numbers is actually recorded.
However, in the total calculation and output respectively
dice ()
Is called, so the displayed value is not used for the total.
Related articles
 html  i would like to know how to calculate the average of the data
 mysql  i would like to know the sql that calculates the total from four tables
 java  i would like to know how to make twitter and evernote an ios or android application
 i would like to know how to solve [literal 9 of type int is out of range] junit unit test java
 calculate total number of elements using javascript filter
 java  calculate the shortest path using dp
 java  [scala] i want to calculate my age when i give birth date
 i would like a code review to check the total number of two dice in python
 java  i would like to see if this complies with my understanding of polymorphism, but can you look at an example?
 java  calculate the average value of the student information class that manages multiple students
 java  i want to calculate the deviation value from command line arguments
 java  i would like to know how to call the original method with the original implementation when using mockito's spy
 about java button creation
 java  calculator i would like to divide it into a number display part and a calculation display part
 java  total points are not displayed
 java  display of the total of each of the three grades
 java  i would like to know about tableau's tabcmd
 html  how to calculate the total value of columns stored in db
 java  i would like to know how to combine two csv files in batch and narrow down where and output
The cause is here
The dice function only describes the process of randomly creating numbers.
So the dice () displayed in print and the dice () performed in sum areIt's a different thing
If you tell me completely, it will not be good for you, so I commented on the pointed out part.
About two hints (almost the answer) of the solution
Let's define a variable once and put it in it instead of displaying dice () directly. Then you can use it for other processing without losing the numerical value.
・ How about calculating the total value every time you ask for a random number?
Something is entered in ○○. It is the same as the one displayed by print, so you should be able to do it by referring to the first hint.
Please do your best.