为了账号安全,请及时绑定邮箱和手机立即绑定

第 21 行显示;预期的

第 21 行显示;预期的

肥皂起泡泡 2021-07-22 18:15:34
第一行包含一个整数 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);        }    }}
查看完整描述

2 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

问题是使用了额外的不必要的括号。改变,

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

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


查看完整回答
反对 回复 2021-07-29
?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

从行尾删除额外的括号)

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


查看完整回答
反对 回复 2021-07-29
  • 2 回答
  • 0 关注
  • 154 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号