有没有办法从我的输出中去掉这个[I@7cc355be?

huangapple go评论84阅读模式
英文:

is there any way that i can remove this [I@7cc355be from my output?

问题

//import java.util.Arrays;
import java.util.*;

public class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int arr[] = new int[size];
        int u=0;
        for (int i = 0; i < size; i++) {
            u=sc.nextInt();
            arr[i] = u;
        }
        System.out.println(Arrays.toString(arr));  // 打印数组内容
        int pos = 0, neg = 0, zero = 0;
        for (int i : arr) {
            if (i > 0) {
                pos += 1;
            } else if (i == 0) {
                zero += 1;
            } else {
                neg += 1;
            }
        }
        System.out.println((double) pos / size);   // 打印正数比例
        System.out.println((double) neg / size);   // 打印负数比例
        System.out.println((double) zero / size);  // 打印零的比例
    }
}
英文:
//import java.util.Arrays;
import java.util.*;

public class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int arr[] = new int[size];
        int u=0;
        for (int i = 0; i &lt; size; i++) {
           u=sc.nextInt();
            arr[i] = u;
        }
        System.out.println(arr);
        int pos = 0, neg = 0, zero = 0;
        for (int i:arr) {
            if (i &gt; 0) {
                pos += 1;
            } else if (i == 0) {
                zero += 1;
            } else {
                neg += 1;
            }
        }
        System.out.println(pos / size);
        System.out.println(neg / size);
        System.out.println(zero / size);
    }
}

this was my code to print the ratio of positive negative and zero's present in my array but in the print statement where i am printing the array, it is showing this [I@7cc355be

答案1

得分: 1

在一行中打印数组的正确方法是:

System.out.println(Arrays.toString(arr));
英文:

The right way to print an array in one line would be:

System.out.println(Arrays.toString(arr));

huangapple
  • 本文由 发表于 2020年9月27日 17:55:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64087141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定