📄 faultexample.java
字号:
import java.io.*;
public class FaultExample
{
public static void main(String[ ] args) throws IOException
{
int[ ] marks = new int[100]; // the marks
int numMarks; // actual number of marks
int sum = 0; // sum of the marks
float average; // average of the marks
int numAbove; // number of marks above average
int numBelow; // number of marks below average
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/* Step 1: Read the marks. */
System.out.println("Enter the marks (enter -1 to finish input)");
numMarks = 0;
do
{
marks[numMarks++] = Integer.parseInt(br.readLine());
} while (marks[numMarks - 1] != -1);
/* Step 2: Compute and display average. */
for (int i = 0; i < numMarks; i++)
sum += marks[i];
average = (float) sum / numMarks;
System.out.println("The average mark is " + average +".");
/* Step 3: Count and display the number of marks above and below average. */
numAbove = 0;
numBelow = 0;
for (int i = 0; i < numMarks; i++)
if (marks[i] >= average)
numAbove++;
else
numBelow++;
System.out.println("There were " + numAbove + " marks above or the same as the average.");
System.out.println("There were " + numBelow + " marks above or the same as the average.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -