【问题标题】:Print the decimal value of each fraction on a new line with 6 places after the decimal在小数点后 6 位的新行上打印每个分数的小数值
【发布时间】:2023-02-07 16:06:09
【问题描述】:

这是我的代码,但我遇到了一些错误,请帮帮我

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(bufferedReader.readLine().trim());

        List<Integer> arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
            .map(Integer::parseInt)
            .collect(toList());

        Result.plusMinus(arr);

        bufferedReader.close();
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        arr[]=new int[N];
        for(int i=0;i<N;i++){
            arr[i]=sc.nextInt();
        }
        plusMinus(List<Integer> arr);
        sc.close();
        
    }
}

我的错误是:

Solution.java:67: error: not a statement
        arr[]=new int[N];
           ^
Solution.java:67: error: ';' expected
        arr[]=new int[N];
             ^
Solution.java:67: error: not a statement
        arr[]=new int[N];
              ^

请让我知道我的错误

【问题讨论】:

  • 请改写你的问题
  • int[] arr = new int[N];,您在声明中缺少数组类型。此外,您列出的名称为arr,不允许在同一范围内重复名称。

标签: java decimal basic


【解决方案1】:

您需要将 arr[]=new int[N]; 替换为 arr.add(N),因为您将 arr 实例化为 List&lt;Integer&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2015-12-19
    相关资源
    最近更新 更多