我的大部分代碼是工作代碼,它只是當我嘗試添加用戶輸入的乘法時,我開始出現錯誤。你能給我建議如何更好地完成或擺脫錯誤?這是我的乘法是錯誤的還是我的整數?
package resittests;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Inputting {
public static void main(String[] args) {
Scanner Scan = new Scanner (System.in); // Creates the Scanner to allow input
System.out.print("Enter a Number");
String input = null;
String first = Scan.next();
int num1 = Integer.parseInt(input);
String Second; // Second Declared as a string
Second = JOptionPane.showInputDialog("Enter Another Number");
String input2 = null;
int num2 = Integer.parseInt(input2);
System.out.print("What is your Name?");
String name = Scan.next();
String Age; // Age Declared as a String
Age = JOptionPane.showInputDialog("Enter your age ");
System.out.print(name + " "+ "(Aged" + " " + Age + ")" + "," + "your answer is " + (num1 * num2));
}
}
「你能給我建議如何做得更好或擺脫錯誤「開始閱讀錯誤,並解決他們通常明確指出的原因。 – ceejayoz
異常在線程 「主」 java.lang.NumberFormatException:空 \t在java.lang.Integer.parseInt(Integer.java:542) \t在java.lang.Integer.parseInt(Integer.java:615) \t (輸入 –
不明白這是什麼 –