Not sure what I’m doing wrong here. But I want to change the card to the correct format.
For example given the card 1c change it to AC.
Here’s some code I’ve been playing with:
public static void main(String[] args) {
String[] cards = {"1c", "13s"};
for (String card : cards) {
switch (card.toUpperCase()) {
case "1C":
card = card.toUpperCase().replace("1C", "AC");
break;
case "13S":
card = card.toUpperCase().replace("13S", "KS");
break;
default:
System.out.println(Arrays.toString(cards));
}
}
System.out.println(Arrays.toString(cards));
}
Any help would be great cheers.
Within the loop,
cardis just a local variable, and reassigning it doesn’t modify the arraycards. An immediate fix would be to index over the array so you can reference each element directly:Edit: to answer edhedges’ comment, one would need to keep a counter variable outside the loop in order to keep using the enhanced-for syntax: