Click here to Skip to main content
14,734,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public void viewPlayer1(int i,int j)
    switch(i && j)
        case 0,case 1 : ImageIcon image1 = new ImageIcon("Plus.jpeg");
                 JLabel label1 = new JLabel(image1);
        case 1,case 1 : ImageIcon image2 = new
                 JLabel label2 = new JLabel(image2);

What I have tried:

how to switch two variable in java ?(use switch case for two variables)
Updated 4-Sep-20 23:47pm

1 solution

You can;t use a switch for two variables, it only works for one.
Java Switch[^]
The expression must evaluate to a single value, which is matched to teh single value in each case statement.

To do what you want, you need a set of if statements:
if (i == 0 && j == 1)
else if (i == 1 && j == 1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900