我在为彩票游戏编写java程序时遇到问题我编写的程序可以正常工作,但是我无法让总和部分正常工作。我需要它添加每一个数字,例如,如果结果打印234,456,345我需要添加2 + 3 + 4 + 4 + 5 + 6 + 3 + 4 + 5然后返回总和但我得到的是234+ 456 + 345任何帮助都会很好。
import java.util.Scanner;
public class LotteryDraw {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int game;
int times;
int randNum;
int lotNum;
int sum = 0;
System.out.println("Which lottery game do you want to play!");
System.out.println("Enter 3 for Pick 3");
System.out.println("Enter 4 for Pick 4");
System.out.println("Enter 5 for Pick 5");
game = input.nextInt();
System.out.print("How many games would you like to play? ");
times = input.nextInt();
System.out.println("Thank you! The numbers selected were: ");
for(int i = 0; i < times; i++) {
lotNum = 0;
for(int j = 0; j < game; j++)
{
randNum = (new java.util.Random()).nextInt(10);
lotNum = (lotNum * 10) + randNum;
System.out.print(randNum);
}
System.out.println();
sum += lotNum;
}
System.out.println("Sum of the numbers of all games: " + sum);
}
}