Hoping someone could help me out with something here, I'm trying to split a long string w/ numbers and card suits so that it displays nicely by number.
AS AC AH AD 2S 2C 2H 2D 3S 3C 3H 3D 4S 4C 4H 4D 5S 5C 5H 5D 6S 6C 6H 6D 7S 7C 7H 7D 8S 8C 8H 8D 9S 9C 9H 9D 10S 10C 10H 10D JS JC JH JD QS QC QH QD KS KC KH KD
would like it to split like:
AS AC AH AD
2S 2C 2H 2D
3S 3C 3H 3D
etc...
Is there a way to use .split() every certain number of characters,etc or by next number?
below is my code to generate a deck of cards
public class Main {
public static void main(String[] args) {
//System.out.printf("hello world");
String cards = "";
char[] suits = {'S', 'C', 'H', 'D'};
for(int i = 1; i <=14; i++){
for(int j = 0; j < suits.length; j++){
if(i == 1){
cards = cards + 'A' + suits[j] + " ";
} else if(i == 11){
break;
} else if(i == 12){
cards = cards + 'J' + suits[j] + " ";
} else if(i == 13){
cards = cards + 'Q' + suits[j] + " ";
} else if(i == 14){
cards = cards + 'K' + suits[j] + " ";
} else {
cards = cards + i + suits[j] + " ";
}
}
}
System.out.println(cards);
}