Do you know what is wrong with my code? I want to initialize two-variable rank and suit together but I can only initialize 1. Do you know how to initialize both to be able to run the program?
Do you know what is wrong with my code? I want to initialize two-variable rank and suit together but I can only initialize 1. Do you know how to initialize both to be able to run the program?
import javax.swing.JOptionPane;
public class Lab3Q5 {
public static void main(String[] args) {
String suit;
String rank = JOptionPane.showInputDialog("Enter a Card");
if (rank.equals("A")) {
rank = "Ace";
}else if (rank.equals("2")){
rank ="Two";
}else if (rank.equals("3")){
rank ="Three";
}else if (rank.equals("4")){
rank ="Four";
}else if (rank.equals("5")){
rank ="Five";
}else if (rank.equals("6")){
rank ="Six";
}else if (rank.equals("7")){
rank ="Seven";
}else if (rank.equals("8")){
rank ="Eight";
}else if (rank.equals("9")){
rank ="Nine";
}else if (rank.equals("10")){
rank ="Ten";
}else if (rank.equals("J")){
rank ="Jack";
}else if (rank.equals("K")){
rank ="King";
}else {
rank ="Queen";
}
if (suit.equals("D")){
suit="Diamonds";
}else if(suit.equals("S")){
suit="Spades";
}else if(suit.equals("C")){
suit="Clubs";
}else {
suit="Hearts";
}
System.out.print(rank+" of "+suit);
}
}
You have not provided the input-output format. so if you have specific input/output in mind. please repost again mentioning the format. I have assumed user input for the card as follows:
input: AD
Output: Ace of Diamond
input: 10H
Output: Ten of Hearts
input: H10
Output: Ten of Hearts
Step by step
Solved in 3 steps with 3 images