当以相同的方式调用时,函数执行不同的操作

时间:2015-07-08 22:03:01

标签: android function

您好我遇到的问题似乎是完全忽略了一行代码或每次都给出不同的结果。

private void getCard() {
    switch (temp4) {

        case 1:
            System.out.println("ACE");
            ValueToBeStored = 11;
            break;
        case 2:
            System.out.println("TEN");
            ValueToBeStored = 10;
            break;
        case 3:
            System.out.println("TWO");
            ValueToBeStored = 2;
            break;
        case 4:
            System.out.println("THREE");
            ValueToBeStored = 3;
            break;
        case 5:
            System.out.println("FOUR");
            ValueToBeStored = 4;
            break;
        case 6:
            System.out.println("FIVE");
            ValueToBeStored = 5;
            break;
        case 7:
            System.out.println("SIX");
            ValueToBeStored = 6;
            break;
        case 8:
            System.out.println("SEVEN");
            ValueToBeStored = 7;
            break;
        case 9:
            System.out.println("EIGHT");
            ValueToBeStored = 8;
            break;
        case 10:
            System.out.println("NINE");
            ValueToBeStored = 9;
            break;
        case 12:
            System.out.println("JACK");
            ValueToBeStored = 10;
            break;
        case 11:
            System.out.println("QUEEN");
            ValueToBeStored = 10;
            break;
        case 13:
            System.out.println("KING");
            ValueToBeStored = 10;
            break;


    }

    {
        switch (CardToBeStored) {

            case 1:
                p1card1 = ValueToBeStored;
                break;
            case 2:
                p1card2 = ValueToBeStored;
                break;
            case 3:
                p1card3 = ValueToBeStored;
                break;
            case 4:
                p1card4 = ValueToBeStored;
                break;
            case 5:
                p1card5 = ValueToBeStored;
                break;
            case 6:
                p2card1 = ValueToBeStored;
                break;
            case 7:
                p2card2 = ValueToBeStored;
                break;
            case 8:
                p2card3 = ValueToBeStored;
                break;
            case 9:
                p2card4 = ValueToBeStored;
                break;
            case 10:
                p2card5 = ValueToBeStored;
                break;
            case 11:
                p3card1 = ValueToBeStored;
                break;
            case 12:
                p3card2 = ValueToBeStored;
                break;
            case 13:
                p3card3 = ValueToBeStored;
                break;
            case 14:
                p3card4 = ValueToBeStored;
                break;
            case 15:
                p3card5 = ValueToBeStored;
                break;
            case 16:
                p4card1 = ValueToBeStored;
                break;
            case 17:
                p4card2 = ValueToBeStored;
                break;
            case 18:
                p4card3 = ValueToBeStored;
                break;
            case 19:
                p4card4 = ValueToBeStored;
                break;
            case 20:
                p4card5 = ValueToBeStored;
                break;
            case 21:
                p5card1 = ValueToBeStored;
                break;
            case 22:
                p5card2 = ValueToBeStored;
                break;
            case 23:
                p5card3 = ValueToBeStored;
                break;
            case 24:
                p5card4 = ValueToBeStored;
                break;
            case 25:
                p5card5 = ValueToBeStored;
                break;
        }

    }

    System.out.println("CARD" + CardToBeStored + " STORED AS " + ValueToBeStored);


}

temp4在调用getCard()之前设置,CardToBeStored也是如此。我的主要问题是,当temp4为11时,QUEEN将在logcat中打印,但ValueToBeStored不会更改为10,而是保留其先前的值。 对于前) getCard()temp-> 4 ValueToBeStored = 4 getCard()temp-> 11 ValueToBeStored = 4 所有其他案件都有效。知道是什么原因引起的吗?如果需要,我可以发送我的整个班级文件。

0 个答案:

没有答案