开发者

m getting an error at default and switch (value),,what is the error?

 import javax.swing.*;
 import java.util.Random;
 import java.util.Scanner;
  class Fifie
 {
    public static void main (String [] args)
    {
        String Iplay;//A ke rock, B ke skere, c is paper
        String PCplay;
        int value;
        Scanner scan = new Scanner(System.in);
        Random num = new Random();

        Iplay = JOptionPane.showMessageDialog("Enter R for rock, P for paper and S for scissors");
         Iplay = scan.next();
         Iplay = Iplay.toUpperCase();
         PCplay = num.nextInt(3);
        switch (value);
        {
            case 0:
                {
                PCplay = "R";
                break;
                }
            case 1:
                {
                PCplay = "P";
                break;
                }
            case 2:

                PCplay = "S";
                break;
                {
        default:
                {
                PCplay = "cannot happen";   
                }
                }
        JOptionPane.showMessageDialog(null,"PCplays: " + PCplays);

        if (Iplay.equals(PCplays))
        {
            JOptionPane.showMessageDialog(null,"tie!"); 
        }   

        else if (Iplay.equals(R) && PCplays.equals(P))
        {
            JOptionPane.showMessageDialog (null, "Paper wraps rock. You lose!");
        }

        else if (Iplay.equals(R) && PCplays.equal (S))
        {
            JOptionPane.showMessageDialog (null, "Rock smashes scissor. You win!");
        }
        else if (Iplay.equals(S) && PCplays.equal(R) )
        {
            JOptionPane.showMessageDialog (null, "Rock smaches scissors. You lose!");
        }
        else if ( Iplay.equals(S) && PCplays.equal (P))
        {
            JOptionPane.showMessageDialog (null, "Scissors cuts paper. You win!");
        }
        else if (Iplay.equals(P) && PCplays.equals(R) )
        {
            JOptionPane.showMessageDialog (null, "Paper covers rock. You wi开发者_如何转开发n!");
        }
        else if (Iplay.equals(P) && PCplays.equals(S))
        {
            JOptionPane.showMessageDialog (null, "Scissor cuts paper. You lose!");
        }

    }


 }
 }


remove the ; from the line switch (value);

read up on java switch/case here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜