System.out.println(B +); else if(r> = 60&& r< 70) System.out。 println(B); else if(r> = 50&& r< 60) System.out.println(C); else if(r> = 40&& r< 50) System.out.println(D); else System.out.println(F); break; 默认值:System.out.println(无效选择); break; } } public void Search()抛出IOException {int f = 0 ; Sysem.out.println(输入要搜索的卷号); int n = Interger.parseInt(br.readLine()); for(int a = 0; a< 40; a ++) {if(n == roll [a]) {f = 1 ; } } if(f == 1) System.out.println(Search成功); 其他 System.out.println(搜索不成功); } public static void Main()抛出IOException {ReportCard Obj = new ReportCard(); Obj.Array(); Obj.Sort (); Obj.Calculate(); Obj.Search(); } } b $ b 我的尝试: switch(ch) {案例1:r = m1 + m2 + m3 + m4; 休息; 此声明给出了n错误: - 二元运算符的错误操作数类型'+' 第一种类型:int [] 第二种类型:int []import java.io.*;class ReportCard{BufferedReader br =new BufferedReader(new InputStreamReader(System.in));int[]roll=new int [40];String[]name=new String [40];int[]num=new int [40];String[]add=new String [40];int[]m1=new int [40];int[]m2=new int [40];int[]m3=new int [40];int[]m4=new int [40];public void Array()throws IOException{for(int a=0;a<40;a++){System.out.println("Enter the roll number");roll[a]=Integer.parseInt(br.readLine());System.out.println("Enter the student's name");name[a]=br.readLine();System.out.println("Enter the phone number");num[a]=Integer.parseInt(br.readLine());System.out.println("Enter the address of student");add[a]=br.readLine();System.out.println("Enter marks in English");m1[a]=Integer.parseInt(br.readLine());System.out.println("Enter marks in Mathematics");m2[a]=Integer.parseInt(br.readLine());System.out.println("Enter the Science");m3[a]=Integer.parseInt(br.readLine());System.out.println("Enter the Computer");m4[a]=Integer.parseInt(br.readLine());}System.out.println("Serial Number \t Roll Number \t Name \t Phone Number \t Address \t English \t Mathematics \t Science \t Computer");for(int b=0;b<40;b++){System.out.println((b+1) + "/t" + roll[b] + "/t" + name[b] + "/t" + num[b] + "/t" + add[b] + "/t" + m1[b] + "/t" + m2[b] + "/t" + m3[b] + "/t" + m4[b]);}}public void Sort()throws IOException{int a,b,t;for(a=0;a<=49;a++)for(b=0;b<=48;b++)if(roll[b]>roll[b+1]){t=roll[b];roll[b]=roll[b+1];roll[b+1]=t;System.out.println("The sorted roll numbers of students are : ");for(a=0;a<=49;a++)System.out.println(roll[a]);}}public void Calculate()throws IOException{int r;System.out.println("1. Total Mark");System.out.println("2. Percentage");System.out.println("3. Average");System.out.println("4. Grade");System.out.println("Enter your choice");int ch=Integer.parseInt(br.readLine());switch(ch){case 1: r=m1+m2+m3+m4; break; case 2: r=(m1+m2+m3+m4)/100; break; case 3: r=(m1+m2+m3+m4)/4; break; case 4: r=(m1+m2+m3+m4)/100; if(r>=90) System.out.println("A+"); else if(r>=80&&r<90) System.out.println("A"); else if(r>=70&&r<80) System.out.println("B+"); else if(r>=60&&r<70) System.out.println("B"); else if(r>=50&&r<60) System.out.println("C"); else if(r>=40&&r<50) System.out.println("D"); else System.out.println("F"); break; default: System.out.println("Invalid Choice"); break;}}public void Search()throws IOException{int f=0;Sysem.out.println("Enter the roll number to be searched");int n=Interger.parseInt(br.readLine());for(int a=0;a<40;a++){if(n==roll[a]){f=1;}}if(f==1)System.out.println("Search Successful");elseSystem.out.println("Search Unsuccessful");}public static void Main()throws IOException{ReportCard Obj=new ReportCard();Obj.Array();Obj.Sort();Obj.Calculate();Obj.Search();}}What I have tried:switch(ch){case 1: r=m1+m2+m3+m4; break;This statement gives an error:-bad operand types for binary operator'+'first type: int []second type: int []推荐答案您不能使用简单的二进制操作数添加数组,并且您当然不能将结果存储在单个整数中。您需要编写一个循环来对各个项目求和。 将来请只显示代码的相关部分,格式正确并包含在< pre>内。标签的可读性,因此:You cannot add arrays with a simple binary operand, and you certainly cannot store the result in a single integer. You need to write a loop to sum the individual items.In future please show only the relevant parts of your code, properly formatted and enclosed within <pre> tags for readability, thus:switch(ch) {case 1: r=m1+m2+m3+m4; break;} 这篇关于如何在此程序中纠正“二元运算符'+''的错误操作数类型的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 01:31