When I run a simple program, both of them ( & and && ) seem to work interchangeably. Could someone please explain when I should use each case?
public class Test1 {
public static void main(String [] args){
int counter = 0;
int dice1;
int dice2;
for (int loop = 0; loop <= 1000; loop++) {
dice1= (int) (Math.random()*6)+1;
dice2= (int) (Math.random()*6)+1;
if (dice1 == 6 && dice2 == 6){
counter ++;
}
}
System.out.println("Counter = " + counter);
}
}
This program also seems to work when I use & instead of &&. So what's the difference?