/*输入三门课程成绩,并计算平均数; 用函数判断:如果平均数>=60,返回合格,否则返回不合格; */ import java.util.Scanner; public class ReturnString { public static void main(String[] args) { Scanner userInput = new Scanner(System.in); double math, english, science; math = userInput.nextDouble(); english = userInput.nextDouble(); science = userInput.nextDouble(); double average = (math + english + science) / 3; System.out.println("average score is " + Math.ceil(average)); System.out.println(pass(average)); } static String pass(double average) { if (average < 60) return "fail"; else return "pass"; } }
注意:java中,函数可以返回String类