public static boolean hasOddStraight(Card[] cards) Five cards (not four) with va
ID: 3567691 • Letter: P
Question
public static boolean hasOddStraight(Card[] cards)
Five cards (not four) with values that are consecutive odd values without "wrapping around" is called an "Odd Straight". For example: 3, 5, 7, 9, J. Keep in mind that the usual order of card values is: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A but see the "important note regarding aces", below.
With straights, the Ace behaves a little different from other cards. It can be used either as the "low end" or as the "high end", but not both to try to "warp around".
The part that i need is how to write the part of the code that keeps the ACE at the low or high card.
example (A,3,5,7,J) -> correct way
(3,5,7,J,A)-> Correct way
(3,A,5,7,J) ->Incorrect way
Explanation / Answer
public static boolean hasOddStraight(Card[] cards)
{
int count =0;
for (int i=0; i<5; i++)
{
if (cards[i]== 'A' or cards[i]=='j' or cards[i]== 'Q' or cards[i]=='K')
{
if (cards[i]=='A')
count++;
if (cards[i]=='Q')
{
return false;
break;
}
}
elseif (cards[i]%2==0)
{
System.out.println("not and odd straight");
return false;
break;
}
}
if (count >1)
{
System.out.println("not and odd straight");
return false;
break;
}
for ( int c = 1; c < 4; c++)
{
if (cards[i]=='A')
{
return false;
break;
}
else
return true;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.