Вот чего я хочу достичь.
Введите:
5
1 2 3 -4 -5 -6 -7 -8 -9
Ожидаемый результат:
The list is 1 2 3 -4 -5.
There are 3 positive numbers and 2 negative numbers.
Пример кода:
String[] s = sc.nextLine().split(" ");
for(int i=0;i<n;i++)
{
...
}
System.out.printf("The list is %s.\nThere are %d positive numbers and %d negative numbers",(s.toString().substring(0,n)),pos,neg);
sc.close();
Вывод:
The list is [Ljav.
There are 3 positive numbers and 2 negative numbers.
Попытался применить Integer.parseint(s.toString().substring(0,n))
с %d
, но затем также получил тот же результат, что и выше. Как это исправить?