我一直收到java:122错误:';。类别';预期。我如何解决它? import java.util.*; public类将{//name类平均为public 公共静态void main(字符串[]args){ Scanner sc=new Scanner(System.in);//使用“new”初始化字符串 弦乐课程; 智力知识标记; 国际通信标志; 智力思维标记; int应用程序标记; 整数平均; 国际终审法院; 国际平均数2; 字符串回答; int-maxK; int-maxC; int-maxA; int最大值; 智力知识权重; 内部通信权重; 智力权重; int应用权重; 字符串赋值; 串试验; int平均值3; 整数权重; 整数加权平均数; int平均值4=0; System.out.println(“你计算的是什么课程?”); Course=Scan.nextLine(); 这个课程你的知识分数是多少; knowledgemark=Scan.nextLine(); 这个课程你的申请分数是多少; applicationmark=Scan.nextLine(); System.out.println(“你对这门课程的想法是什么?”); thinkingmark=Scan.nextLine(); System.out.println(“你在本课程中的沟通分数是多少?”); communicationmark=Scan.nextLine(); 平均得分=((知识分数+交流分数+应用分数+思维分数)/4); 平均值=Scan.nextInt(); System.out.println(“你的“+课程+”的平均值是“+平均值”); System.out.println(“你想用期末考试分数计算你的考试吗?(是或否)”; answer=Scan.next(); 如果(回答等于(“是”)){ System.out.println(“你的期末考试分数是多少?”); finalexam=scan.nextInt(); 平均数2=((平均数*70)+最终数*30)/100); System.out.println(“您在本课程中的最终平均成绩为”+average2); } 否则{ System.out.println(“你对“+课程+”的平均值是“+平均值”); } System.out.println(“您还可以通过测试/作业计算分数”); Test=Scan.nextLine(); System.out.println(“你在计算什么测试/作业?”); Test=Scan.nextLine(); System.out.println(“知识的权重是多少?”); knowledgeweight=Scan.nextLine(); System.out.println(“你在考试/作业中的知识分数是多少?”); maxK=Scan.nextLine(); System.out.println(“通信的权重是多少?”); 通信权重=Scan.nextLine(); System.out.println(“您在测试/作业中的通信标记是什么?”); maxC=Scan.nextLine(); System.out.println(“应用程序的权重是多少?”); applicationweight=Scan.nextLine(); System.out.println(“你的考试/作业申请分数是多少?”); maxA=Scan.nextLine(); System.out.println(“知识的权重是多少?”); thinkingweight=Scan.nextLine(); System.out.println(“你对测试/作业的想法是什么?”); maxT=Scan.nextLine(); 平均值3=(maxK*知识权重+maxC*通信权重+maxT*思考权重+maxA*应用权重); System.out.println(“您此次测试/作业的最终平均值为”+平均值3); System.out.println(“测试/分配(10,30,50)的权重是多少?”; 加权平均值=Scan.nextInt; 加权平均值=(平均值3*加权平均值); System.out.println(“您的作业/测试加权为”+加权平均值); 整数长度; 扫描仪扫描=新扫描仪(System.in); System.out.println(“您有多少类?”); 长度=scan.nextInt(); int[]firstArray=新的int[length]; 对于(int i=0;i
您在对位于的我一直收到java:122错误:';。类别';预期。我如何解决它? import java.util.*; public类将{//name类平均为public 公共静态void main(字符串[]args){ Scanner sc=new Scanner(System.in);//使用“new”初始化字符串 弦乐课程; 智力知识标记; 国际通信标志; 智力思维标记; int应用程序标记; 整数平均; 国际终审法院; 国际平均数2; 字符串回答; int-maxK; int-maxC; int-maxA; int最大值; 智力知识权重; 内部通信权重; 智力权重; int应用权重; 字符串赋值; 串试验; int平均值3; 整数权重; 整数加权平均数; int平均值4=0; System.out.println(“你计算的是什么课程?”); Course=Scan.nextLine(); 这个课程你的知识分数是多少; knowledgemark=Scan.nextLine(); 这个课程你的申请分数是多少; applicationmark=Scan.nextLine(); System.out.println(“你对这门课程的想法是什么?”); thinkingmark=Scan.nextLine(); System.out.println(“你在本课程中的沟通分数是多少?”); communicationmark=Scan.nextLine(); 平均得分=((知识分数+交流分数+应用分数+思维分数)/4); 平均值=Scan.nextInt(); System.out.println(“你的“+课程+”的平均值是“+平均值”); System.out.println(“你想用期末考试分数计算你的考试吗?(是或否)”; answer=Scan.next(); 如果(回答等于(“是”)){ System.out.println(“你的期末考试分数是多少?”); finalexam=scan.nextInt(); 平均数2=((平均数*70)+最终数*30)/100); System.out.println(“您在本课程中的最终平均成绩为”+average2); } 否则{ System.out.println(“你对“+课程+”的平均值是“+平均值”); } System.out.println(“您还可以通过测试/作业计算分数”); Test=Scan.nextLine(); System.out.println(“你在计算什么测试/作业?”); Test=Scan.nextLine(); System.out.println(“知识的权重是多少?”); knowledgeweight=Scan.nextLine(); System.out.println(“你在考试/作业中的知识分数是多少?”); maxK=Scan.nextLine(); System.out.println(“通信的权重是多少?”); 通信权重=Scan.nextLine(); System.out.println(“您在测试/作业中的通信标记是什么?”); maxC=Scan.nextLine(); System.out.println(“应用程序的权重是多少?”); applicationweight=Scan.nextLine(); System.out.println(“你的考试/作业申请分数是多少?”); maxA=Scan.nextLine(); System.out.println(“知识的权重是多少?”); thinkingweight=Scan.nextLine(); System.out.println(“你对测试/作业的想法是什么?”); maxT=Scan.nextLine(); 平均值3=(maxK*知识权重+maxC*通信权重+maxT*思考权重+maxA*应用权重); System.out.println(“您此次测试/作业的最终平均值为”+平均值3); System.out.println(“测试/分配(10,30,50)的权重是多少?”; 加权平均值=Scan.nextInt; 加权平均值=(平均值3*加权平均值); System.out.println(“您的作业/测试加权为”+加权平均值); 整数长度; 扫描仪扫描=新扫描仪(System.in); System.out.println(“您有多少类?”); 长度=scan.nextInt(); int[]firstArray=新的int[length]; 对于(int i=0;i,java,Java,您在对位于的nextInt()的调用中缺少()) import java.util.*; public class Averages{ //name class as public public static void main(String[] args){ Scanner sc = new Scanner(System.in); //initialized string using 'new' String Course; int kn
nextInt()
的调用中缺少()
)
import java.util.*;
public class Averages{ //name class as public
public static void main(String[] args){
Scanner sc = new Scanner(System.in); //initialized string using 'new'
String Course;
int knowledgemark;
int communicationmark;
int thinkingmark;
int applicationmark;
int average;
int finalexam;
int average2;
String answer;
int maxK;
int maxC;
int maxA;
int maxT;
int knowledgeweight;
int communicationweight;
int thinkingweight;
int applicationweight;
String Assignment;
String Test;
int average3;
int weight;
int weightaverage;
int average4= 0;
System.out.println("What class are you calculating for?");
Course = Scan.nextLine();
System.out.println("What's your knowledge mark for this course?");
knowledgemark = Scan.nextLine();
System.out.println("What's your application mark for this course?");
applicationmark = Scan.nextLine();
System.out.println("What's your thinking mark for this course?");
thinkingmark = Scan.nextLine();
System.out.println("What's your communication mark for this course?");
communicationmark = Scan.nextLine();
average = ((knowledgemark + communicationmark + applicationmark + thinkingmark)/4);
average = Scan.nextInt();
System.out.println("Your average for" + Course + "is" + average);
System.out.println("Do you want to calculate your exam with your final exam mark? (yes or no)");
answer = Scan.next();
if(answer.equals ("yes")){
System.out.println("What is your final exam mark?");
finalexam = scan.nextInt();
average2 = (((average * 70) + finalexam * 30) /100);
System.out.println("Your final average in this course is" + average2);
}
else{
System.out.println("You average for" + Course + "is" + average);
}
System.out.println("You can also calculate your marks with tests/assignments");
Test = Scan.nextLine();
System.out.println("What test/assignment are you calculating for?");
Test = Scan.nextLine();
System.out.println("What is the weighting for knowledge?");
knowledgeweight = Scan.nextLine();
System.out.println("What is your knowledge mark for the test/assignment?");
maxK = Scan.nextLine();
System.out.println("What is the weighting for communication?");
communicationweight = Scan.nextLine();
System.out.println("What is your communication mark for the test/assignment?");
maxC = Scan.nextLine();
System.out.println("What is the weighting for application?");
applicationweight = Scan.nextLine();
System.out.println("What is your application mark for the test/assignment?");
maxA = Scan.nextLine();
System.out.println("What is the weighting for knowledge?");
thinkingweight = Scan.nextLine();
System.out.println("What is your thinking mark for the test/assignment?");
maxT = Scan.nextLine();
average3 = (maxK * knowledgeweight + maxC * communicationweight + maxT * thinkingweight + maxA * applicationweight);
System.out.println("Your final average for this test/assignment is" + average3);
System.out.println("What is the weight of the test/assignment (10, 30, 50)?");
weightaverage = Scan.nextInt;
weightaverage = (average3 * weightaverage);
System.out.println("Your assignment/test weighted is" + weightaverage);
int length;
Scanner scan = new Scanner(System.in);
System.out.println("How many classes do you have?");
length = scan.nextInt();
int[] firstArray = new int[length];
for(int i=0; i<length; i++){
System.out.println("What is your course mark for each class in order" + (1 + i) + "?");
firstArray[i] = scan.nextInt[];
}
}
}
把它改成
weightaverage = Scan.nextInt;
和
weightaverage = Scan.nextInt();
应该是
firstArray[i] = scan.nextInt[];
和,您与您的扫描仪
名称不一致
firstArray[i] = scan.nextInt();
需要
Scanner sc = new Scanner(System.in);
如果您要调用
Scan.nextLine()
。同时,您要调用nextLine()
(它返回一个字符串
),并将结果分配给int
变量。下面是根据Elliott Frisch的建议更正的代码
重申:
- 您使用变量名
声明了sc
,但在代码的其余部分使用了Scanner
。更正为Scan.nextLine()
sc.nextLine()
无法转换为字符串。它返回一个整数,例如,sc.nextLine()
是正确的int knowledgemark=sc.nextLine();
- 某些代码正在使用
或sc.nextInt;
应更正为sc.nextInt[];
sc.nextInt();
import java.util.*; public类将{//name类平均为public 公共静态void main(字符串[]args){ Scanner sc=new Scanner(System.in);//使用“new”初始化字符串 弦乐课程; 智力知识标记; 国际通信标志; 智力思维标记; int应用程序标记; 整数平均; 国际终审法院; 国际平均数2; 字符串回答; int-maxK; int-maxC; int-maxA; int最大值; 智力知识权重; 内部通信权重; 智力权重; int应用权重; 字符串赋值; 串试验; int平均值3; 整数权重; 整数加权平均数; int平均值4=0; System.out.println(“什么类
Scanner Scan = new Scanner(System.in);
import java.util.*; public class Averages { //name class as public public static void main(String[] args) { Scanner sc = new Scanner(System.in); //initialized string using 'new' String Course; int knowledgemark; int communicationmark; int thinkingmark; int applicationmark; int average; int finalexam; int average2; String answer; int maxK; int maxC; int maxA; int maxT; int knowledgeweight; int communicationweight; int thinkingweight; int applicationweight; String Assignment; String Test; int average3; int weight; int weightaverage; int average4 = 0; System.out.println("What class are you calculating for?"); Course = sc.nextLine(); System.out.println("What's your knowledge mark for this course?"); knowledgemark = sc.nextInt(); System.out.println("What's your application mark for this course?"); applicationmark = sc.nextInt(); System.out.println("What's your thinking mark for this course?"); thinkingmark = sc.nextInt(); System.out.println("What's your communication mark for this course?"); communicationmark = sc.nextInt(); average = ((knowledgemark + communicationmark + applicationmark + thinkingmark) / 4); average = sc.nextInt(); System.out.println("Your average for" + Course + "is" + average); System.out.println("Do you want to calculate your exam with your final exam mark? (yes or no)"); answer = sc.next(); if (answer.equals("yes")) { System.out.println("What is your final exam mark?"); finalexam = sc.nextInt(); average2 = (((average * 70) + finalexam * 30) / 100); System.out.println("Your final average in this course is" + average2); } else { System.out.println("You average for" + Course + "is" + average); } System.out.println("You can also calculate your marks with tests/assignments"); Test = sc.nextLine(); System.out.println("What test/assignment are you calculating for?"); Test = sc.nextLine(); System.out.println("What is the weighting for knowledge?"); knowledgeweight = sc.nextInt(); System.out.println("What is your knowledge mark for the test/assignment?"); maxK = sc.nextInt(); System.out.println("What is the weighting for communication?"); communicationweight = sc.nextInt(); System.out.println("What is your communication mark for the test/assignment?"); maxC = sc.nextInt(); System.out.println("What is the weighting for application?"); applicationweight = sc.nextInt(); System.out.println("What is your application mark for the test/assignment?"); maxA = sc.nextInt(); System.out.println("What is the weighting for knowledge?"); thinkingweight = sc.nextInt(); System.out.println("What is your thinking mark for the test/assignment?"); maxT = sc.nextInt(); average3 = (maxK * knowledgeweight + maxC * communicationweight + maxT * thinkingweight + maxA * applicationweight); System.out.println("Your final average for this test/assignment is" + average3); System.out.println("What is the weight of the test/assignment (10, 30, 50)?"); weightaverage = sc.nextInt(); weightaverage = (average3 * weightaverage); System.out.println("Your assignment/test weighted is" + weightaverage); int length; Scanner scan = new Scanner(System.in); System.out.println("How many classes do you have?"); length = scan.nextInt(); int[] firstArray = new int[length]; for (int i = 0; i < length; i++) { System.out.println("What is your course mark for each class in order" + (1 + i) + "?"); firstArray[i] = scan.nextInt(); } } }