我正在製作一個代碼,它從用戶那裏接收卡片並將它們放入卡片組中,卡片的值取決於數字,例如1然後5將是5的心3然後13將是黑桃王。如果卡插入正確,它應該返回true,否則應該拋出異常,應該檢查卡組中的空間,如果沒有,應該返回false,最後如果卡已經插入,它應該返回false。錯誤在評論中。爲什麼我在Eclispe中遇到這些錯誤?
import java.util.Scanner;
public static void main(String[] args){ //red underline error on void saying "syntax error token", under the second bracket of String[] and on the last bracket after args.
private static addCards(){
String suit[] = {"Hearts", "Diamonds", "Spades", "Clubs"};
String value[] = {"ZZZZ", "Ace", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "Jack", "Queen", "King"};
String[] card = new String[52];
String[] newSuit = new String[4];
Scanner input = new Scanner(System.in); //it says it expects a { instead of the semicolon here.
for (int i = 0; i < 52; i++){
System.out.println("Please enter a suit");
int inputSuit = input.nextInt();
check = false;
if(inputSuit = 1 || 2 || 3 || 4){
check = true;
}
System.out.println("Please enter a card");
int inputValue = input.nextInt();
check1 = false;
if(inputValue = 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13){
check1 = true;
}
try{
check = true;
check1 = true;
}
catch(card exception){
ex.printStackTrace();
System.exit(1);
}
switch (inputSuit) {
case 0: newSuit[i] = suit[0]; break;
case 1: newSuit[i] = suit[1]; break;
case 2: newSuit[i] = suit[2]; break;
case 3: newSuit[i] = suit[3]; break;
}
switch (inputValue) {
case 1: card[i] = value[1]; break;
case 2: card[i] = value[2]; break;
case 3: card[i] = value[3]; break;
case 4: card[i] = value[4]; break;
case 5: card[i] = value[5]; break;
case 6: card[i] = value[6]; break;
case 7: card[i] = value[7]; break;
case 8: card[i] = value[8]; break;
case 9: card[i] = value[9]; break;
case 10: card[i] = value[10]; break;
case 11: card[i] = value[11]; break;
case 12: card[i] = value[12]; break;
case 13: card[i] = value[13]; break;
}
boolean isFull = true;
for(String s : card) {
if(s == null) {
isFull = false;
break;
}
}
}
} //"multiple markers in this line"
您不能在Java中的方法中使用方法。 –
你的班級名稱是什麼? – Pshemo