hey again i've fixed my code a little and need a little help. I've got the flush and one pair determinations to work but the three of a kind, straight, straight flush and royal straight flush are giving me a little trouble. If anyone has any suggestions, i would really appreciate the help my code is below
By the way, for the straight determination, i could only get rank numbers that are close to each other, like 2, 3, 4 to make Straight output. Numbers like 2,15,4 which = 2,3,4 when it outputs doesnt output straight

import java.util.Random;

public class midterm_exam 
{
    public static void main(String[] args) 
    {
Random generating = new Random();
int card2, card3, cardSuit2, cardSuit3, cardRank2, cardRank3, cardSuit, cardRank, card;
String suit, rank, suit2, rank2, suit3, rank3;

        card = generating.nextInt(52);
        card2 = generating.nextInt(52);
        card3 = generating.nextInt(52);
        cardRank = card%13;
        cardRank2 = card2%13;
        cardRank3 = card3%13;
        cardSuit = card/13;
        cardSuit2 = card2/13;
        cardSuit3 = card3/13;

                if(cardSuit==1)
                    suit = "Hearts";  
                else if(cardSuit==2)
                    suit = "Diamonds"; 
                else if(cardSuit==3)
                    suit = "Clubs";
                else 
                    suit = "Spades";  

                if(cardSuit2==1)
                    suit2 = "Hearts"; 
                else if(cardSuit2==2)
                    suit2 = "Diamonds";
                else if(cardSuit2==3)
                    suit2 = "Clubs";
                else 
                    suit2 = "Spades";

                if(cardSuit3==1)
                    suit3 = "Hearts";
                else if(cardSuit3==2)
                    suit3 = "Diamonds";
                else if(cardSuit3==3)
                    suit3 = "Clubs";
                else 
                    suit3 = "Spades";

if(cardRank==0 || cardRank==13 || cardRank==26 || cardRank==39)
                    rank = "Ace";else if(cardRank==1 || cardRank==14 || cardRank==27 || cardRank==40)
                    rank = "Two";
else if(cardRank==2 || cardRank==15 || cardRank==28 || cardRank==41)
                    rank = "Three";
else if(cardRank==3 || cardRank==16 || cardRank==29 || cardRank==42)
                    rank = "Four";
else if(cardRank==4 || cardRank==17 || cardRank==30 || cardRank==43)
                    rank = "Five";
else if(cardRank==5 || cardRank==18 || cardRank==31 || cardRank==44)
                    rank = "Six";
else if(cardRank==6 || cardRank==19 || cardRank==32 || cardRank==45)
                    rank = "Seven";
else if(cardRank==7 || cardRank==20 || cardRank==33 || cardRank==46)
                    rank = "Eight";
else if(cardRank==8 || cardRank==21 || cardRank==34 || cardRank==47) 
                    rank = "Nine";
else if(cardRank==9 || cardRank==22 || cardRank==35 || cardRank==48) 
                    rank = "Ten";
 else if(cardRank==10 || cardRank==23 || cardRank==36 || cardRank==49)
                    rank = "Jack";
                else if(cardRank==11 || cardRank==24 || cardRank==37 || cardRank==50)
                    rank = "Queen";
                else
                    rank = "King";

                if(cardRank2==0 || cardRank2==13 || cardRank2==26 || cardRank2==39)
                    rank2 = "Ace";
                else if(cardRank2==1 || cardRank2==14 || cardRank2==27 || cardRank2==40)
                    rank2 = "Two";
                else if(cardRank2==2 || cardRank2==15 || cardRank2==28 || cardRank2==41)
                    rank2 = "Three";
                else if(cardRank2==3 || cardRank2==16 || cardRank2==29 || cardRank2==42)
                    rank2 = "Four";
                else if(cardRank2==4 || cardRank2==17 || cardRank2==30 || cardRank2==43)
                    rank2 = "Five";
                else if(cardRank2==5 || cardRank2==18 || cardRank2==31 || cardRank2==44)
                    rank2 = "Six";
                else if(cardRank2==6 || cardRank2==19 || cardRank2==32 || cardRank2==45)
                    rank2 = "Seven";
                else if(cardRank2==7 || cardRank2==20 || cardRank2==33 || cardRank2==46)
                    rank2 = "Eight";
                else if(cardRank2==8 || cardRank2==21 || cardRank2==34 || cardRank2==47) 
                    rank2 = "Nine";
                else if(cardRank2==9 || cardRank2==22 || cardRank2==35 || cardRank2==48) 
                    rank2 = "Ten";
                else if(cardRank2==10 || cardRank2==23 || cardRank2==36 || cardRank2==49)
                    rank2 = "Jack";
                else if(cardRank2==11 || cardRank2==24 || cardRank2==37 || cardRank2==50)
                    rank2 = "Queen";
                else
                    rank2 = "King";

                if(cardRank3==0 || cardRank3==13 || cardRank3==26 || cardRank3==39)
                    rank3 = "Ace";
                else if(cardRank3==1 || cardRank3==14 || cardRank3==27 || cardRank3==40)
                    rank3 = "Two";
                else if(cardRank3==2 || cardRank3==15 || cardRank3==28 || cardRank3==41)
                    rank3 = "Three";
                else if(cardRank3==3 || cardRank3==16 || cardRank3==29 || cardRank3==42)
                    rank3 = "Four";
                else if(cardRank3==4 || cardRank3==17 || cardRank3==30 || cardRank3==43)
                    rank3 = "Five";
                else if(cardRank3==5 || cardRank3==18 || cardRank3==31 || cardRank3==44)
                    rank3 = "Six";
                else if(cardRank3==6 || cardRank3==19 || cardRank3==32 || cardRank3==45)
                    rank3 = "Seven";
                else if(cardRank3==7 || cardRank3==20 || cardRank3==33 || cardRank3==46)
                    rank3 = "Eight";
                else if(cardRank3==8 || cardRank3==21 || cardRank3==34 || cardRank3==47) 
                    rank3 = "Nine";
                else if(cardRank3==9 || cardRank3==22 || cardRank3==35 || cardRank3==48) 
                    rank3 = "Ten";
                else if(cardRank3==10 || cardRank3==23 || cardRank3==36 || cardRank3==49)
                    rank3 = "Jack";
                else if(cardRank3==11 || cardRank3==24 || cardRank3==37 || cardRank3==50)
                    rank3 = "Queen";
                else
                    rank3 = "King";

                System.out.println("Card 1 is a " + rank + " of " + suit);
                System.out.println("Card 2 is a " + rank2 + " of " + suit2);
                System.out.println("Card 3 is a " + rank3 + " of " + suit3);

                int x = cardRank-cardRank2;
                int ex = cardRank2-cardRank3;

                if((Math.abs(x)==1)&&(Math.abs(ex)==1))//test for straight
                    System.out.println("Straight");

                if((cardSuit==0)&&(cardSuit2==0)&&(cardSuit3==0))//test for flush
                    System.out.println("Flush");
                else if((cardSuit==1)&&(cardSuit2==1)&&(cardSuit3==1))
                    System.out.println("Flush");
                else if((cardSuit==2)&&(cardSuit2==2)&&(cardSuit3==2))
                    System.out.println("Flush");
                else if((cardSuit==3)&&(cardSuit2==3)&&(cardSuit3==3))
                    System.out.println("Flush");
                else if((rank==rank2)&&(rank2==rank3))// test for three of a kind
                    System.out.println("Three pair");
                else if((rank==rank2)||(rank2==rank3)||(rank==rank3))// test for one pair
                    System.out.println("Two pair");

                else if(((Math.abs(x)==1)&&(Math.abs(ex)==1))&&((cardSuit==0)&&(cardSuit2==0)&&(cardSuit3==0)))//test for straight flush
                    System.out.println("Straight Flush");

                /*else if()//test for royal straight flush
                    System.out.println("Royal Straight Flush");*/

Edited 3 Years Ago by Dani: Formatting fixed

1. Are you sure, that your example is correct 2,15,4 which = 2,3,4 ... and not 16 = 3?
2. You don't check the case, when you get, for example 4,2,3. In that case your (x == 2) and (ex == 1), but it is still Straight.
P.S. If the first part of your problem (I mean thread "determine type of card hand") is solved, mark it solved, please :)

hii bro
your codes work properly but you are missing braces at the end of the method.

System.out.println("Straight Flush");

good luck

This question has already been answered. Start a new discussion instead.