3つのカードポーカーゲームを作成しようとしていて、 "式の型は配列型でなければなりません私が困惑しているintに解決されたエラーです。このエラーは、私がカウンターをやり遂げたのと似ていないようですが、私はコーディングでかなり新しいので、エラーの内容を理解できません。私が推測しなければならないのは、私の方法を言うだろうが、それはjavaになるとかなり無知だ。その下に3つの場所があり、エラーが発生しています。私は私に問題を与える部分とその下のコード全体を含めました。どんな助けもありがとうございます。ここでカウンタエラー "式の型は配列型である必要がありますが、それはint型に解決されました"
//This method will determine if the player has a pair
public static int pair(String main)
{
int check = 0;
int card1;
int card2;
for(int counter = 1; counter <3; counter++) //error here
{
if (card1[counter - 1] == card2[counter])
{
check++;
}
}
if (check == 1)
{
return 1;
}
else
{
return 0;
}
}
//This method will tell the player if he has a high card
public static int highcard(String main)
{
int highcard = 0;
int card1;
int card2;
for (int counter = 0; counter < 3; counter++)
{
if (card1[counter] > highcard) // error here
{
highcard = card1[counter]; // error here
}
}
return highcard;
}
コード
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
//Setting variables
int card1;
int card2;
int card3;
int faceValue1;
int faceValue2;
int faceValue3;
int suit1;
int suit2;
int suit3;
int suit4;
Random g = new Random();
card1 = g.nextInt(51)+1;
card2 = g.nextInt(51)+1;
card3 = g.nextInt(51)+1;
suit1 = g.nextInt(3)+1;
suit2 = g.nextInt(3)+1;
suit3 = g.nextInt(3)+1;
suit4 = g.nextInt(3)+1;
}
public static String FaceValue(String main){
//Making the players hand
int card1;
int card2;
int card3;
int faceValue1;
int faceValue2;
int faceValue3;
int suit;
int suit1;
int suit2;
int suit3;
int suit4;
faceValue1 = card1 /4 + 2;
faceValue2 = card2/4 + 2;
faceValue3 = card3 /4 + 2;
System.out.println(faceValue1);
System.out.println(faceValue2);
System.out.println(faceValue3); }
//setting up a method to convert the cards and suit to a string
public static String convert(String main){
int card1;
int card2;
int card3;
int faceValue1;
int faceValue2;
int faceValue3;
int suit;
int suit1;
int suit2;
int suit3;
int suit4;
suit = card1 % 4;
//Converting card and suit 1
if (faceValue1 == 1)
{
System.out.print("Ace of ");
}
if (faceValue1 == 2)
{
System.out.print("Two of ");
}
if (faceValue1 == 3)
{
System.out.print("Three of ");
}
if (faceValue1 == 4)
{
System.out.print("Four of ");
}
if (faceValue1 == 5)
{
System.out.print("Five of ");
}
if (faceValue1 == 6)
{
System.out.print("Six of ");
}
if (faceValue1 == 7)
{
System.out.print("Seven of ");
}
if (faceValue1 == 8)
{
System.out.print("Eight of ");
}
if (faceValue1 == 9)
{
System.out.print("Nine of ");
}
if (faceValue1 == 10)
{
System.out.print("Ten of ");
}
if (faceValue1 == 11)
{
System.out.print("Jack of ");
}
if (faceValue1 == 12)
{
System.out.print("Queen of ");
}
if (faceValue1 == 13)
{
System.out.print("King of ");
}
if (suit1 == 1)
{
System.out.print("Spades");
System.out.println();
}
if (suit1 == 2)
{
System.out.print("Hearts");
System.out.println();
}
if (suit1 == 3)
{
System.out.print("Diamonds");
System.out.println();
}
if (suit1 == 4)
{
System.out.print("Clubs");
System.out.println();
}
//Converting card and suit 2
if (faceValue2 == 1)
{
System.out.print("Ace of ");
}
if (faceValue2 == 2)
{
System.out.print("Two of ");
}
if (faceValue2 == 3)
{
System.out.print("Three of ");
}
if (faceValue2 == 4)
{
System.out.print("Four of ");
}
if (faceValue2 == 5)
{
System.out.print("Five of ");
}
if (faceValue2 == 6)
{
System.out.print("Six of ");
}
if (faceValue2 == 7)
{
System.out.print("Seven of ");
}
if (faceValue2 == 8)
{
System.out.print("Eight of ");
}
if (faceValue2 == 9)
{
System.out.print("Nine of ");
}
if (faceValue2 == 10)
{
System.out.print("Ten of ");
}
if (faceValue2 == 11)
{
System.out.print("Jack of ");
}
if (faceValue2 == 12)
{
System.out.print("Queen of ");
}
if (faceValue2 == 13)
{
System.out.print("King of ");
}
if (suit2 == 1)
{
System.out.print("Spades");
System.out.println();
}
if (suit2 == 2)
{
System.out.print("Hearts");
System.out.println();
}
if (suit2 == 3)
{
System.out.print("Diamonds");
System.out.println();
}
if (suit2 == 4)
{
System.out.print("Clubs");
System.out.println();
}
// Converting card and suit 3
if (faceValue3 == 1)
{
System.out.print("Ace of ");
}
if (faceValue3 == 2)
{
System.out.print("Two of ");
}
if (faceValue3 == 3)
{
System.out.print("Three of ");
}
if (faceValue3 == 4)
{
System.out.print("Four of ");
}
if (faceValue3 == 5)
{
System.out.print("Five of ");
}
if (faceValue3 == 6)
{
System.out.print("Six of ");
}
if (faceValue3 == 7)
{
System.out.print("Seven of ");
}
if (faceValue3 == 8)
{
System.out.print("Eight of ");
}
if (faceValue3 == 9)
{
System.out.print("Nine of ");
}
if (faceValue3 == 10)
{
System.out.print("Ten of ");
}
if (faceValue3 == 11)
{
System.out.print("Jack of ");
}
if (faceValue3 == 12)
{
System.out.print("Queen of ");
}
if (faceValue3 == 13)
{
System.out.print("King of ");
}
if (suit3 == 1)
{
System.out.print("Spades");
System.out.println();
}
if (suit3 == 2)
{
System.out.print("Hearts");
System.out.println();
}
if (suit3 == 3)
{
System.out.print("Diamonds");
System.out.println();
}
if (suit3 == 4)
{
System.out.print("Clubs");
System.out.println();
}
System.out.println("Your hand is " + faceValue1 + suit1 +"," + faceValue2 + suit2 + "," + faceValue3 + suit3);
}
//This method will determine if the player has a flush
public static int flush(String main)
{
int suit2;
int suit1;
for (int counter = 1; counter < 3; counter++)
{
if (suit1 != suit2)
{
return 1;
}
}
return 0;
}
//This method will determine if the player has a straight
public static int straight(String main)
{
int card1;
int card2;
for (int counter2 = 1; counter2 < 3; counter2++)
if (card1[counter2 - 1] != (card2[counter2] - 1))
{
return 1;
}
return 1;
}
//This method will determine if the player has three of a kind
public static int threekind(String main)
{
int card1;
int card2;
int card3;
if (card1 == card2 && card2 == card3)
{
return 1;
}
return 0;
}
//This method will determine if the player has a pair
public static int pair(String main)
{
int check = 0;
int card1;
int card2;
for(int counter = 1; counter <3; counter++)
{
if (card1[counter - 1] == card2[counter])
{
check++;
}
}
if (check == 1)
{
return 1;
}
else
{
return 0;
}
}
//This method will tell the player if he has a high card
public static int highcard(String main)
{
int highcard = 0;
int card1;
int card2;
for (int counter = 0; counter < 3; counter++)
{
if (card1[counter] > highcard)
{
highcard = card1[counter];
}
}
return highcard;
}
/* This method will evaluates the hand and see what the player has
and give the player an output of their hand*/
public static int evaluate(String main)
{
if (flush() == 1)
{
System.out.println("You have a flush!");
}
else if (straight() == 1)
{
System.out.println("You have a straight!");
}
else if (threekind() == 1)
{
System.out.println("You have a three of a kind!");
}
else if (pair() == 1)
{
System.out.println("You have a pair!");
}
else
{
int highCard = highCard();
System.out.println("Your highest card is " + highCard);
}
}
}
}}
なぜ整数を添字にしようとしていますか?また、なぜあなたは役に立たないメソッドパラメータを持っていますか? – Li357