簡體   English   中英

輸入無法解析:使用Scanner類和數組

[英]input cannot be resolved : Using Scanner class and Array

導入java.util.Scanner; 類Arrayy {

public static void main(String a[])
{
    Scanner sc = new Scanner (System.in);
    double arr[] = new double[5];
    for (int i = 1 ; i<arr.length; i++)
    {
        System.out.println("Enter The Stuff: ");     
        arr[i] = **input**.nextInt();

    }
}
}

我將其標記為粗體的地方顯示了“輸入無法解析”的例外情況

有人可以幫忙嗎,盡管它很基本。

您的Scanner變量稱為sc ,而不是input

public static void main(String a[])
{
    Scanner sc = new Scanner (System.in);
    double arr[] = new double[5];
    for (int i = 1 ; i<arr.length; i++)
    {
        System.out.println("Enter The Stuff: ");     
        arr[i] = sc.nextInt();

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM