猿问

第 21 行显示;预期的

第一行包含一个整数 p,表示数组的长度。第二行包含用空格分隔的整数,描述数组中的每个相应元素。第三行打印一个整数,表示负数组的数量。


package asgn3;


import java.util.*;


public class Asgn3 {


    public static void main(String[] args) {


        int count = 0, result = 0;

        Scanner in = new Scanner(System.in);

        System.out.println("Enter the array ");

        String s = in.nextLine();

        int j = 0;

        String[] s1 = s.split(" ");

        int a[] = new int[s1.length];


        for(String s2:s1) {

            a[j] = Integer.parseInt(s2));

            j++;

        }


        for (int i = 0; i < a.length; i++) {

            for ( j = i; j < a.length; j ++) {

                for (int k = i; k <= j; k++) {

                    result += a[k];

                }


                if(result < 0)

                    count ++;

            }

            System.out.println("no. of negatve arrays is "+count);

        }

    }

}


肥皂起泡泡
浏览 155回答 2
2回答

慕桂英4014372

问题是使用了额外的不必要的括号。改变,a[j]=Integer.parseInt(s2));和a[j]=Integer.parseInt(s2);

牛魔王的故事

从行尾删除额外的括号)a[j]&nbsp;=&nbsp;Integer.parseInt(s2);
随时随地看视频慕课网APP

相关分类

Java
我要回答