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[];
}
}
}
这是我的代码。错误在页面底部附近。提前谢谢!
请帮我解决此问题,因为我不知道该怎么办
这是我剩下的唯一要编译的错误。
谢谢,不胜感激!
编辑:格式化为在一个代码段中显示代码。
你缺少()
在调用nextInt()
时
weightaverage = Scan.nextInt;
将其更改为类似
weightaverage = Scan.nextInt();
和
firstArray[i] = scan.nextInt[];
应该
firstArray[i] = scan.nextInt();
并且,您的名字与您的名字不一致Scanner
。
Scanner sc = new Scanner(System.in);
需要是
Scanner Scan = new Scanner(System.in);
如果你要打电话Scan.nextInt()
。另外,您正在调用nextLine()
(返回String
)并将结果分配给int
变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句