日期:2014-05-20 浏览次数:20796 次
public List getOper(){ int k=0; if(getOpera.size()==0){ if(cbAdd.isSelected()){ getOpera.add(k,'+'); k++; }else if(cbSub.isSelected()){ getOpera.add(k,'-'); k++; }else if(cbMul.isSelected()){ getOpera.add(k,'*'); k++; }else if(cbDiv.isSelected()){ getOpera.add(k,'/'); k++; } } return getOpera; } public char choiceOper(){ getOper(); Random ranOp = new Random(); int i=ranOp.nextInt(getOpera.size()); System.out.println(getOpera.size()); return (Character) getOpera.get(i); }
public List getOper(){ int k=0; getOpera.clear(); //每次都清空getOpera,然后重新追加用户选择的符号 //if(getOpera.size()==0){ //这个if不要,否则如果getOpera有元素以后就不会再追加了 if(cbAdd.isSelected()){ getOpera.add(k,'+'); k++; } if(cbSub.isSelected()){ //不要用else if,否则满足if就不会进入else if,就不能有多个值了 getOpera.add(k,'-'); k++; } if(cbMul.isSelected()){ //这里一样 getOpera.add(k,'*'); k++; } if(cbDiv.isSelected()){ //这里一样 getOpera.add(k,'/'); k++; } //} return getOpera; } public char choiceOper(){ getOper(); Random ranOp = new Random(); int i=ranOp.nextInt(getOpera.size()); //这样这里才有意义 System.out.println(getOpera.size()); return (Character) getOpera.get(i); }