我想添加更多的命令到我的java程序我寫在unix,但有問題傳遞參數。我剛纔輸入了unix命令之前的文本文件作爲程序參數,它工作得很好,但是想要求輸入。試圖修復它在我自己的,但一點點新的Java從輸入解析字符串作爲參數問題
我有,
public static void main(String[] args)
{
String input = args[0];
///
String count = args[1];
File newF = new File(input); //
StartProcess start = new StartProcess(input, Integer.parseInt(count)); //begin
}
這工作就好了,然後想這一點,它未能
public static void main(String[] args)
{
//String inputFile = args[0]; //read the input file
Scanner scanner = new Scanner(new InputStreamReader(System.in));
System.out.println("Please enter file");
String input = scanner.nextLine();
System.out.println("Please enter number");
int count = scanner.nextInt();
//String interruptCounter = args[1]; //read the interrupt value
File newFile = new File(input); //create a new file with the input file
StartProcess being = new StartProcess(input, Integer.parseInt(count)); //begin
}
所以我得到了這些錯誤
CPU.java:24:錯誤:不兼容的類型 int count = scanner.nextLine(); ^ 需要:整數 發現:字符串 CPU.java:27:錯誤:實測parseInt函數(INT) StartProcess是=新StartProcess(輸入,的Integer.parseInt(計數))沒有合適的方法; (實際參數int不能通過方法調用轉換轉換爲字符串) 方法Integer.parseInt和正式參數列表的長度不同) 2錯誤
編譯錯誤似乎不是你粘貼的代碼。根據我的代碼應該編譯好。 – Neo 2014-10-04 22:44:55