[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Java Programming Help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 2

File: 1404202805672.jpg (51KB, 720x480px) Image search: [Google]
1404202805672.jpg
51KB, 720x480px
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...
>>
File: ancap_twhe.jpg (143KB, 512x512px) Image search: [Google]
ancap_twhe.jpg
143KB, 512x512px
>>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
Thread posts: 13
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.