?? 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 + -