[英]Getting a public static void class to read an array from another class
这里是说类
public static void showCodes(){
System.out.print(" Select from");
System.out.print(" => ");
for (String show : productDB.inventory)
{ System.out.print(show.toUpperCase() + " ");}
System.out.print(" <=");
}
这是另一个类(具有数组)
public class ProductDB
{
public String[] inventory = {"java", "jsps", "mcb2", "txtp", "calc", "topg", "bigl", "sgtp"};
**insert rest of class code**
}
这是我的主要
public static void main(String args[])
{
System.out.println(" Product Selection\n");
showCodes();
...
我知道我需要定义我的变量,但我对 Java 还很陌生。 在第 4 行的第一个块代码中,出现“找不到符号”错误。
将方法showCodes
中的for
循环更改for
:
for (String show : ProductDB.inventory)
并将static
添加到类中的数组定义中,如下所示:
public static String[] inventory = {"java", "jsps", "mcb2", "txtp", "calc", "topg", "bigl", "sgtp"};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.