英文:
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 < 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 > 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));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论