我有一個問題傳遞給構造函數的多個數組。 我們真的可以做到嗎?如何將多個數組傳遞給java中的構造函數?
public class First {
public String[] a;
public String[] b;
public First(String[] a, String[] b){
this.a=a;
this.b=b;
}
}
而下一個代碼是我在哪裏使用class First。
Scanner ss = new Scanner(System.in);
int x;
System.out.print("How many lines? ");
x = ss.nextInt();
for(int i=0; i<x; i++){
System.out.print("A: "); a[i]=ss.nextString();
System.out.print("B: "); b[i]=ss.nextString();
}
First ff= new First(a,b);
在NetBeans中,沒有錯誤,但我不能在另一個類中使用它。
如果你願意幫助我,我會很感激。
我的意思是我也會做出從用戶的程序輸入,而不是我們把價值從第一次。 'Scanner ss = new Scanner(System.in); int x; System.out.print(「多少行?」); x = ss.nextInt(); 對(INT I = 0; I
Embek
嗨@ @Embek ...請檢查下面的代碼.... – kaushik
@Embek請檢查我的第一個ans。它工作正常.. – kaushik