2015-10-05 55 views
-4
  • 如何通过公共函数获取一维数组的内容?

这是我的公共方法从函数返回一维数组,如何?

public class try 
{ 
    private String sname; 
    private int[][] score; 
    private int grade; 
    private double average; 

    public void names(String[] stuname) 
    { 
     String[] sname = new String[3]; 
     sname[0] = "Blair"; 
     sname[1] = "Waldorf"; 
     sname[2] = "Chuck"; 

    } 
} 

那么这是我在其他类文件的主要方法。

public class MainTry 
{ 
    public static void main(String[] args) 
    { 
     try a1 = new try(); 
     System.out.println(a1.sname[3]); 
    } 
} 

有一个很大的错误。我无法得到它。即时通讯使用netbeans。

+1

发布您已经尝试过。或者至少试着在你的问题上更精确。这种问题不容易回答,并不适合堆栈溢出。 –

回答

0
// declare a string array with initial size 
String[] names = new String[4]; 

// remember that the array starts at 0 so an array with 4 elements goes up to index number 3. 
// add elements to the array 
names[0] = "Freddy"; 
names[1] = "Fish"; 
names[2] = "Henry"; 
names[3] = "Tom"; 

这是如何制作一个名称的一维数组。

+0

一个名字....不是n个名字。但不清楚他是否喜欢维数为1的字符串或其他不同的字符串 –

+0

我只需要编程中的一个名称选项卡。因为我需要将成绩放在二维名称的旁边。谢谢阁下:) –

+0

你自己弄明白了吗?还是你还遇到同样的问题? – Derk