public static void main(String[] args){
/*让用户输入列表数的个数*/
System.out.print("enter the size of the list");
Scanner input=new Scanner(System.in);
int geshu=input.nextInt();
/*让用户输入列表*/
int [] shuzu=new int[geshu];
System.out.print("enter the contents of the list:");
for(int i=0;i<geshu;i++){
shuzu[i]= input.nextInt();
}
/*检查是否升序*/
int a=shuzu[0];
for(int j=1;j<geshu;j++){
if(shuzu[j]>=a){
a=shuzu[j];
continue;
}
else {
boolean buer=true;
break;
}
}
/*显示结果*/
System.out.print("the list has 9 integers :"+shuzu[++]);/*expression expected*/
if(buer==true){/*cannot resolve symbol 'buer' */
System.out.print("the list is already sorted");
}
else
System.out.print("the list is not sorted");
}
用户指定列表个数并输入列表,判断该列表是否升序,我代码有两错误,帮我看看要怎么改,thanks
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 字菁悠心 2021-10-16 20:46关注
第25行没有看懂,第26行buer没有定义为方法里面的全局变量,是有问题的,建议改成如下:
public static void main(String[] args){ /*让用户输入列表数的个数*/ System.out.print("enter the size of the list"); Scanner input=new Scanner(System.in); int geshu=input.nextInt(); /*让用户输入列表*/ int [] shuzu=new int[geshu]; System.out.print("enter the contents of the list:"); for(int i=0;i<geshu;i++){ shuzu[i]= input.nextInt(); } /*检查是否升序*/ int a=shuzu[0]; boolean buer=false; for(int j=1;j<geshu;j++){ if(shuzu[j]>=a){ a=shuzu[j]; continue; } else { buer=true; break; } } /*显示结果*/ System.out.print("the list has 9 integers :"+shuzu.length);/*expression expected*/ if(buer==true){/*cannot resolve symbol 'buer' */ System.out.print("the list is already sorted"); } else System.out.print("the list is not sorted"); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 请分析一下这个电路设计的优点🙏
- ¥15 求视频摘要youtube和ovp数据集
- ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
- ¥15 在启动roslaunch时出现如下问题
- ¥15 汇编语言实现加减法计算器的功能
- ¥20 关于多单片机模块化的一些问题
- ¥30 seata使用出现报错,其他服务找不到seata
- ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
- ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
- ¥15 Google speech command 数据集获取