So, I'm writing a program that lets a user play poker, essentially.
I'm trying to go about checking for the different hands (full house, straight flush, etc) by sorting an array storing the value of the cards in ascending order.
I know that I can use Arrays.sort(array) to do this. However, it doesn't seem to be working in my program, since I wrote a quick for loop to print out the sorted array, and it isn't sorted. Here's a code segment from my program.
I know, I know, I could be looping this if statement and save memory but this isn't about optimization right now.
int[] value = {9, 7, 8, 6, 5};
int[] suit = {1,1,1,1,1};
Arrays.sort(value);
for(int i = 0; i < 5; i++){
Arrays.sort(value);
System.out.print(value[i]);
}
if(value[0] == (value[1] + 1) && value[1] == (value[2] + 1) && value[2] == (value[3] + 1) && value[3] == (value[4] + 1)){
if (suit[0] == suit[1] && suit[1] == suit[2] && suit[2] == suit[3]){
System.out.println("");
System.out.println("You were dealt a Straight Flush.");
}
}
For whatever reason the array isnt being sorted, so what is going on?
>>59117908
kill yourself
Have you tried turning the pc on and off?
>>59118236
you know you can use code blocks here newfag
>>59117908
value = Arrays.sort(value)
>>59117908
oh what the fuck
There's no need to sort it inside of the loop...
>>59117908
see >>59118259
and see >>59118282
The same applies to regex replace methods and other things as well. It's a consequence of the pass reference by value model Java has and it's a good thing actually.
int[] value = {9, 7, 8, 6, 5};
int[] suit = {1,1,1,1,1};
Arrays.sort(value);
for (int i = 0; i < 5; i++){
Arrays.sort(value);
System.out.print(value[i]);
}
if(value[0] == (value[1] + 1) && value[1] == (value[2] + 1) && value[2] == (value[3] + 1) && value[3] == (value[4] + 1)){
if (suit[0] == suit[1] && suit[1] == suit[2] && suit[2] == suit[3]){
System.out.println("");
System.out.println("You were dealt a Straight Flush.");
}
}
here's your code block dummy
>>59118454
>>59118282
stop stop stop... dont do this faggots homework for him.
If you're not trolling (which I assume you're not) just go to reddit.
https://www.reddit.com/r/learnjava/
Don't ever post programming help here since /g/ is pretty much a circlejerk of which Linux distro is better and shit like that. But if you really want to stay on 4chan then go to /dpt/, /g/'s own programming thread.
>>59116218
Have fun.
>>59118489
How do I do this?
>>59118560
>actually helping homework threads