java如何以IPO格式放置代码?
我已经为一个程序编写了代码,但我没有在代码中使用方法,我想知道如何在代码中实现方法
我知道基本结构应该包括输入、处理和输出
都在这里:
import java.io.*;
public class Question {
public static void main(String[] args) throws IOException {
String name = null;
float mark, total, average, totalAverage = 0;
int totalNumberOfPeople = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println ("Average Calc.\n");
do {
total = 0;
System.out.print("Name: ");
try {
name = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
if(!name.equalsIgnoreCase("end")) {
totalNumberOfPeople++;
System.out.println("Enter marks for " + name + ".");
for(int i=1; i <= 5; i++) {
System.out.print("Enter mark #" + i + " of 5: ");
try {
mark = Float.parseFloat(br.readLine());
}
catch(NumberFormatException nfe) {
mark = 0;
}
catch (IOException e) {
mark = 0;
}
total = total + mark;
}
average = (float)total / 5;
System.out.println("\nThe average of the 5 marks entered is " + average);
totalAverage = totalAverage + average;
}
}
while(!name.equalsIgnoreCase("end"));
System.out.println("Total number of people = " + totalNumberOfPeople);
System.out.println("Final average = " + totalAverage / totalNumberOfPeople );
}
}
# 1 楼答案
您可以尝试使用以下方法进行分离: