0
在我的一个方法中有一个名为“量”的变量,但我需要在另一个方法中引用它。我不确定使用的语法。初始化在方法外部使用的实例变量
下面是代码:
public static void startup()
{
String message = "Welcome to Toronto Mutual!";
//prompts user to enter their employee ID
String logIn = JOptionPane.showInputDialog("Please enter your employee `enter code here`ID.");
int employeeID = Integer.parseInt(logIn);
String input = JOptionPane.showInputDialog("Please enter the transaction `enter code here`type, bank ID and amount all separated by a comma.");
input=input.toUpperCase();
if (input.equals("END")){
JOptionPane.showMessageDialog(null,"Goodbye.");
System.exit(0);
}
else
{
int balance = 100;
String []transaction = new String[3];
transaction = input.split(",");
String type = transaction[0];
int bankID = Integer.parseInt(transaction[1]);
type=type.toUpperCase();
... // there's more but it's irrelevant
如何使用变量“量”和“bankID”的方法之外?
我看不到代码'amount'。 – kasavbere 2012-04-04 23:49:07
代码中没有看到“金额”和“bankID”。但是如果你真的需要用另一种方法引用它,只需在启动()方法之外初始化它即可。 '私人字符串的数量;'并在这种方法中做任何你想要的。你可以从另一种方法阅读它 - 只要确保你按照正确的顺序来调用它。 – 2012-04-05 00:47:15
或者将其作为参数传递给需要它的方法。 – 2013-06-02 16:55:26