所以,我是超新的Java,但我正在嘗試製作一個特定於類的程序,以便我可以在Java中進行遊戲。這裏是我的代碼:如何正確使用Java方法?
import java.util.Scanner;
public class boxtype {
public static void main(String args[]) {
String[] melee = {"Crowbar", "Bowie Knife", "Butterfly Knife", "Knuckleduster"};
String[] pistol = {"Colt .22", "Magnum .45", "P250", "9mm Pistol"};
String[] assault = {"AK47", "M4A1", "M16", "SMG", "Mac10", "Minigun (HGE)"};
String[] shotgunsniper = {"Shotgun", "Benelli S90", "Sniper Rifle"};
String[] attachments = {"Laser Sight", "Silencer", "Scope", "Auto-target"};
Scanner scan = new Scanner(System.in);
String xy = scan.nextLine();
if (xy.equals("spyclass")) {
spyClass();
}
}
private static void spyClass(String[] assault, String[] attachments, String[] pistol) {
// TODO Auto-generated method stub
System.out.println("Spy class: ");
System.out.println("Primary weapon: " + assault[2] + " + " + attachments[2]);
System.out.println("Secondary weapon: " + pistol[1] + " + " + attachments[2]);
System.out.println("");
}
}
基本上會發生什麼,就是Eclipse返回一個錯誤,指出「spyClass不適用」。我仍在研究如何解決,但是。
呼叫
你有太多的花括號。除去'spyClass'方法之上的一個。 – Makoto