Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlackJack2 {
- public static int maxIndex(int[] arr) {
- int max = 0, index = 0;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i] > max)
- max = arr[i];
- }
- for (int j = 0; j < arr.length; j++) {
- if(arr[j] == max)
- index = j;
- }
- return index;
- }
- public static void main(String[] args) {
- int[] cards = new int[10];
- int[] playerTotal = new int[10];
- for (int l = 0; l < 10; l++) {
- System.out.println("player " + l + " : ");
- for (int i = 0; i < 10; i++) {
- cards[i] = (int) (10 * Math.random() + 1);
- System.out.print(cards[i] + " ");
- }
- for (int k = 0; k < 10; k++) {
- playerTotal[l] += cards[k];
- }
- System.out.println("total = " + playerTotal[l]);
- }
- System.out.println("the winner is player " + maxIndex(playerTotal));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment