java - Adding the output of Stack.pop() -


import java.util.random; import java.util.stack;  public class blackjack {   public static void main(string[] args) {     int cardvalue; /* card value 2 11 */     stack player1 = new stack();     stack addition = new stack();      random r = new random();     int = 2 + r.nextint(11);      system.out.println("welcome mitchell's blackjack program!");      (int = 1; <= 2; a++) { /* start's game assigning 2 cards each, players */       player1.push(i);     }      while (!player1.empty()) {       system.out.print("you " + player1.pop());       system.out.print("and");        int sum = 0;        (int n = 0; n < player1.size(); n++) {         sum = sum + player1.pop();         system.out.print("your total " + sum);       }     }   } } 

so started learning java , i'm trying accomplish blackjack project but, when try compile using javac output bad operand types binary operator '+' 'sum = sum + player1.pop();'

the solution used in above coding here

player1.pop() returns object because used stack without providing type. , cannot int + object. if need store ints in stack, use generics , do

stack<integer> player1 = new stac<integer>k(); stack<integer> addition = new stack<integer>(); 

and your

system.out.print("your total " + sum); 

should outside otherwise temporary sum


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -