Help required please

I am working on a program to roll a set of dice 1000 times and count the occurences of the doubles. I am also required to count the occurences of each of the doubles but I am getting an error on compile my code is:

publicclass TestDice

{

publicstaticvoid p(String s)

{

System.out.print(s);

}

publicstaticvoid main(String[] args)

{

PairOfDice dice;

int noRolls,doubles=0;

int bin1=0;

dice =new PairOfDice();

p("\n\n");

for (noRolls=0; noRolls<100; noRolls++)

{

dice.roll();

p("" + dice.getDice1() +"," + dice.getDice2() +"\t");

if(dice.getDice1() == dice.getDice2())

doubles++;

if(dice.getDice1() && dice.getDice2() == 1)

bin1++;

}

p("\n\nThere was " + doubles +" Doubles \n\n");

p("\n\nThere was " + bin1 +" Double 1's \n\n");

}

}

the compiler output is saying:

public class TestDice

{

public static void p(String s)

{

System.out.print(s);

}

public static void main(String[] args)

{

PairOfDice dice;

int noRolls,doubles=0;

int bin1=0;

dice = new PairOfDice();

p("\n\n");

for (noRolls=0; noRolls<100; noRolls++)

{

dice.roll();

p("" + dice.getDice1() + "," + dice.getDice2() + "\t");

if(dice.getDice1() == dice.getDice2())

doubles++;

if(dice.getDice1() && dice.getDice2() == 1)

bin1++;

}

p("\n\nThere was " + doubles + " Doubles \n\n");

p("\n\nThere was " + bin1 + " Double 1's \n\n");

}

}

any help would be greatly appreciated thanks

[2583 byte] By [JP_Traininga] at [2007-10-2 17:09:22]
# 1
sorry the compiler output is: Compiler Output TestDice.java:28: operator && cannot be applied to int,booleanif(dice.getDice1() && dice.getDice2() == 1)^1 error--
JP_Traininga at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...
# 2
What's the error, and on which line is is ocurring? Paste the complete error message in.Also, please use a meainingful subject next time.
jverda at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...
# 3
sorry that was a mistake on what i was pasting in, the error occurs in the second if statement
JP_Traininga at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...
# 4

> sorry the compiler output is:

>

> Compiler Output

>

> TestDice.java:28: operator && cannot be applied to

> int,boolean

>if(dice.getDice1() && dice.getDice2() == 1)

It means exactly what it says.

getDice1() returns an int. getDice2() == 1 is a boolean ( == has higher precedence than && apparently).

You're bascally doing this: if ( 1 && (a == b) )

I assume you want to test for both d1 and d2 being 1. That wold be if (d1 == 1 && d2 == 1)

But that's pointless. You only need to test one of them, since you already know they're equal: if (d1 == d2) {

increment total count of doubles

increment count corresponding to the number of pips on d1

}

Also, I would not use separate variables for the various doubles counts. Just one int for the total, and an array for the individual pips' doubles counts. You should not even have anything like if (d1 == 1)

at all.

jverda at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...
# 5
thanks for the help I will take your points on board cheers : )
JP_Traininga at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...
# 6
Oh, and if you're not familiar with arrays... http://java.sun.com/docs/books/tutorial/java/data/arrays.html
jverda at 2007-7-13 18:24:14 > top of Java-index,Java Essentials,Java Programming...