你好,我必须首先制作一个程序我要求登录代码我放了一个try/catch
因为我希望密码只有数字,如果给一个字符来刺激异常,第二个不是显示对象数组Product
而是一个字符串Productl@pos51sd
和我找不到为什么要给我看这个。
import java.rmi.Naming;
import java.util.Scanner;
public class RMIClient {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int pin=0;
try {
String name = "//Localhost/RMI_Server";
Functions lp =(Functions)Naming.lookup(name);
try{
System.out.println("Please give your Personal Code (PIN)");
pin=in.nextInt();
}catch (NumberFormatException nfe) {
System.out.println("Input must be a number.");
}
if(lp.validate(pin)){
System.out.println("Give description of item");
String desc=in.next();
int sizep=lp.search(desc).length;
Product [] p =new Product[sizep];
System.arraycopy(lp.search(desc),0,p,0,sizep);
for(int i=0;i<sizep;i++){
System.out.println(p[i].toString());}
System.out.println("Give numberCode of item you want to buy");
String code=in.next();
System.out.println(lp.purchase(code));
}else{
System.out.println("Your code is False");}
lp.close();
}catch (Exception e) {
System.out.println("SumClient err: " + e);
System.exit(1);
}
}
}