import java.util.Random;
public class PP59 {
public static void main(String[] args) {
int Random1, Random2, Random3;
Random generator = new Random();
while (in.hasNextLine()) {
Random1 = generator.nextInt(9);
Random2 = generator.nextInt(9);
Random3 = generator.nextInt(9);
System.out.print(Random1);
System.out.print(Random2);
System.out.println(Random3);
if (Random1 == Random2 && Random1 == Random3 || Random2 == Random1 && Random2 == Random3 || Random3 == Random1 && Random3 == Random2) {
System.out.println("You won £50 :D/>");
}
if (Random1 == Random2 || Random2 == Random3 || Random1 == Random3) {
System.out.println("You won £25 :D/>");
}
}
}
}
3 Replies - 178 Views - Last Post: 16 February 2012 - 10:18 AM
#1
Can you show me an improved version of my program?
Posted 16 February 2012 - 09:50 AM
Cheers if you can. I'm trying to see how I could my this program more readable. The aim is too make a slot machine which tells you, you win if you the same numbers.
Replies To: Can you show me an improved version of my program?
#2
Re: Can you show me an improved version of my program?
Posted 16 February 2012 - 10:13 AM
In the line:
Where is declared 'in' ?.
And this is most readable.
while (in.hasNextLine())
Where is declared 'in' ?.
And this is most readable.
if ( (Random1 == Random2 && Random1 == Random3 ) || (Random2 == Random1 && Random2 == Random3)
|| (Random3 == Random1 && Random3 == Random2) ) {
System.out.println("You won £50 :D/>");
}else if ( (Random1 == Random2) || (Random2 == Random3) || (Random1 == Random3) ) {
System.out.println("You won £25 :D/>");
}
#3
Re: Can you show me an improved version of my program?
Posted 16 February 2012 - 10:18 AM
Ahhh Cheers that looks a lot better. Thanks for the tips
#4
Re: Can you show me an improved version of my program?
Posted 16 February 2012 - 10:18 AM
You don't need the extra blank lines; a source file header that describes what the file does, who wrote it and when would be nice; an appropriate comment now and then; and better variable names - avoid using the same subscripted name over and over.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|