t0xicv4p0r

Untitled

Mar 30th, 2019
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. public class BlackJack2 {
  2.  
  3.     public static int maxIndex(int[] arr) {
  4.         int max = 0, index = 0;
  5.         for (int i = 0; i < arr.length; i++) {
  6.             if (arr[i] > max)
  7.                 max = arr[i];
  8.         }
  9.  
  10.         for (int j = 0; j < arr.length; j++) {
  11.             if(arr[j] == max)
  12.                 index = j;
  13.         }
  14.         return index;
  15.        
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.  
  20.         int[] cards = new int[10];
  21.         int[] playerTotal = new int[10];
  22.  
  23.         for (int l = 0; l < 10; l++) {
  24.             System.out.println("player " + l +  " : ");
  25.             for (int i = 0; i < 10; i++) {
  26.                 cards[i] = (int) (10 * Math.random() + 1);
  27.                 System.out.print(cards[i] + " ");
  28.  
  29.             }
  30.  
  31.             for (int k = 0; k < 10; k++) {
  32.                 playerTotal[l] += cards[k];
  33.             }
  34.  
  35.             System.out.println("total = " + playerTotal[l]);
  36.         }
  37.  
  38.         System.out.println("the winner is player " + maxIndex(playerTotal));
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment