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");
}
第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");
}