Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中,我可以不使用循环从一行输入中读取多个整数吗_Java_Input_Integer_Line_Stdout - Fatal编程技术网

在Java中,我可以不使用循环从一行输入中读取多个整数吗

在Java中,我可以不使用循环从一行输入中读取多个整数吗,java,input,integer,line,stdout,Java,Input,Integer,Line,Stdout,我遇到了一个问题,就是找一段代码将一组整数读入一个列表,我尝试了这个方法,但没有成功: 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;

我遇到了一个问题,就是找一段代码将一组整数读入一个列表,我尝试了这个方法,但没有成功:

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);
    }
}

试试这个示例代码,看看它是否适合您

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);
    }
}

问:我可以不使用循环从一行输入中读取多个整数吗

A.并行处理,可能是;但是对于正常的顺序处理,不,总是会涉及到一个循环

问:但是,如果没有并行处理的好处,我是否可以从一行输入中读取多个整数,而不必使用循环语句
for
while
,或
do


A:是的,有溪流。但是不要认为通过消除显式循环语句,您已经消除了实际的循环本身;它仍然在那里,只是隐藏在流机制中,而不是在您自己的代码中清晰可见。

Q:我可以不使用循环从一行输入中读取多个整数吗

A.并行处理,可能是;但是对于正常的顺序处理,不,总是会涉及到一个循环

问:但是,如果没有并行处理的好处,我是否可以从一行输入中读取多个整数,而不必使用循环语句
for
while
,或
do

A:是的,有溪流。但是不要认为通过消除显式循环语句,您已经消除了实际的循环本身;它仍然在那里,只是隐藏在流式机器中,而不是在您自己的代码中清晰可见。

“in”是nothing,“stdOut”是noting,您也没有列表,我不明白您实际上在做什么“in”是nothing,“stdOut”是noting,您也没有列表,我不明白您实际上在做什么