Ayman101:
私は私がこれを試みたが、無駄に、リストに整数の束を読み取るためにコードの一部を見つける問題を持っています:
public static void main(String[] args){
int[] a = in.readInts(); //in cannot be resolved
StdOut.println(count(a)); //StdOut cannot be resolved
}
あなたは私を助けてくださいことはできますか?
打者:
この例のコードを試してみてください、それはあなたのために働くかどうかを確認します。
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int amount = 3; // Amount of integers to be read, change it at will.
Scanner reader = new Scanner(System.in);
System.out.println("Please input your numbers: ");
int num; // integer will be stored in this variable.
// List that will store all the integers.
ArrayList<Integer> List = new ArrayList<Integer>();
for (int i = 0; i < amount; ++i) {
num = reader.nextInt();
List.add(num);
}
System.out.println(List);
}
}
入力とコンソールでこのコード1 2 3
利回り:
Please input your numbers:
1 2 3
[1, 2, 3]