我可以在主類中做這樣的事嗎?創建多個對象
Scanner sc = new Scanner(System.in);
System.out.println("message 1");
int nbre1 = sc.nextInt();
sc.nextLine();
System.out.println("message 2");
int nbre2 = sc.nextInt();
sc.nextLine();
System.out.println("message 3");
int nbre3 = sc.nextInt();
sc.nextLine();
Obj o = new Obj(nbre1, nbre2, nbre3);
// print a message "do you want to create another object?"
如果是,我可以再次顯示消息但不影響其他對象的變量,例如: O2?
是的,你做這樣的事情,很明顯我想既然你已經做了:-) – Thihara 2013-03-12 06:30:52
我怎麼都找不到! – mpluse 2013-03-12 06:31:48
當然,它不會工作,因爲'sc'無處定義。 – dokaspar 2013-03-12 06:32:19