【发布时间】:2015-06-10 19:13:46
【问题描述】:
public void TheBank() {
Scanner Sc = new Scanner(System.in);
System.out.println("Please Enter your Username and Password");
MemoryStorage();// Stores the Username and Password in the system.
VariableCompare();// Compares the Username and Password to see if they match or do not
}
private void MemoryStorage(){// this should just be here to store the variables username and password
Scanner Sc = new Scanner(System.in);
String username = Sc.nextLine();
String password = Sc.nextLine();
}
private void VariableCompare() {// this should compare to see if they match or dont and print the results
if (username.equals (password){
System.out.println("Please try again your Username and Password cannot be the same");
} else {
System.out.println (" Your username is:" + username);
System.out.println(" Your password is:" + password);
}
}
}
我的问题是主体(MemoryStorage),我希望它保存用户名和密码,以便其他主体也可以使用它进行计算。目前,其他机构不接受变量用户名和密码,我想知道如何使这两个变量可供所有机构使用。
【问题讨论】:
-
然后将用户名和密码设为实例变量。
标签: java variables global private