简体   繁体   English

找不到适合 println 的方法... Java

[英]No suitable method found for println... Java

I am trying to test my arrays that I stored in variables by displaying the first int/double/string stored under a method called displayMessage.我试图通过显示存储在名为 displayMessage 的方法下的第一个 int/double/string 来测试我存储在变量中的数组。 However for some reason whenever I make the method I get the error, No suitable method found for println..., for my Println statement.但是,出于某种原因,每当我使用该方法时,都会出现错误,找不到适合 println... 的合适方法,对于我的 Println 语句。 Any and all help would be fantastic!任何和所有的帮助都会很棒! thanks in advance, below is the code.提前致谢,下面是代码。

public class InventoryClass {
    private int[] itemNumber = {1,2,3,4,5,6,7,8,9,10};
    private String[] productName={"CD1","CD2","CD3","CD4","CD5","CD6","CD7","CD8","CD9","CD10"};
    private int[] unitsInStock={2,14,22,11,5,20,7,9,14,31};
    private double[] productPrice={4.99, 9.99, 4.99, 9.99, 7.99, 7.99, 14.50, 9.99, 9.99, 4.99};




    public void displayMessage(){
        System.out.println(itemNumber[1], productName[1], unitsInStock[1], productPrice[1]);}

Change: 更改:

System.out.println(itemNumber[1], productName[1], unitsInStock[1], productPrice[1]);

To: 至:

System.out.println(itemNumber[1] +" "+ productName[1] +" "+ unitsInStock[1] +" "+ productPrice[1]);

You're trying to pass 4 arguments to println but it only takes one. 您正在尝试将4个参数传递给println但只使用一个。

Read the manual next time. 下次阅读手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM