我看到这已经被回答了几次,但是我很难理解这些答案,甚至更难以将它们应用到我的程序中。该程序基本上计算2个数字的总和,并将它们转换为百分比,但值不能超过75.我使用if方法来解决这个问题,但在书中它说"(提示:使用math.min) ",所以我担心,如果我不能在项目上失分。如果有人可以帮助我实现最大值,那就太棒了。
package week2assignments;
import java.util.Scanner;
public class Question4
{
public static void main(String[] args)
{
int memberRent;
int memberRef;
double memberDisc;
Scanner in = new Scanner(System.in);
System.out.println("How many rentals has the user made?");
memberRent = in.nextInt();
System.out.println("How many members has the user reffered?");
memberRef = in.nextInt();
memberDisc = memberRent + memberRef;
if(memberDisc > 75)
{
memberDisc = 75;
}
System.out.printf("Member has a discount of: ");
System.out.printf("%.2f \n", memberDisc);
}
}