当前位置: 技术问答>java相关
如何让函数返回一个m*n的数组(m大小不固定)
来源: 互联网 发布时间:2015-04-03
本文导语: 怎么返回一个长度不固定的2维数组? 返回后怎么引用它 能给个例子吗? THANKS. | import java.awt.*; import java.awt.event.*; public class MyApp extends Frame { public MyApp() { this.addWindowListener (new WindowA...
怎么返回一个长度不固定的2维数组?
返回后怎么引用它
能给个例子吗?
THANKS.
返回后怎么引用它
能给个例子吗?
THANKS.
|
import java.awt.*;
import java.awt.event.*;
public class MyApp extends Frame
{
public MyApp()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public String[][] tt()
{
int i =3;
int p =9;
String s[][] = new String[i][p];
s[0][0] = "a";
return s;
}
public static void main(String args[])
{
System.out.println("Starting App");
MyApp f = new MyApp();
String s[][] = f.tt();
System.out.println(s[0][0]);
f.setSize(100,100);
f.show();
}
}
import java.awt.event.*;
public class MyApp extends Frame
{
public MyApp()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public String[][] tt()
{
int i =3;
int p =9;
String s[][] = new String[i][p];
s[0][0] = "a";
return s;
}
public static void main(String args[])
{
System.out.println("Starting App");
MyApp f = new MyApp();
String s[][] = f.tt();
System.out.println(s[0][0]);
f.setSize(100,100);
f.show();
}
}
|
为什么不返回一个可变的Vector呢?