gpt4 book ai didi

java - 方法返回零

转载 作者:行者123 更新时间:2023-11-29 07:16:02 24 4
gpt4 key购买 nike

假设返回 19 个完整座位和剩余 68 个学生的值!请帮忙,据我所知,我正在返回正确的值并将它们分配给正确的变量!

public class JetCalculator
{
public static void main(String[] args)
{
int totalStudents = 3013;
int jetCapacity = 155;
int jets;
int students;
jets = calculateJets(jetCapacity, totalStudents);
students = calculateStudents(jetCapacity, totalStudents, jets);

System.out.println("A total of "+ totalStudents + " student require "+ jets + " full seated jets.");
System.out.println("There will be " + students + " students remaining");
System.out.println("_____________________________________________");
System.out.println(jets);
System.out.println(jetCapacity);
System.out.println(students);
}

public static int calculateJets(int totalStudents, int jetCapacity)
{
int fullJets;
fullJets = totalStudents / jetCapacity;
return fullJets;
}

public static int calculateStudents( int jetCapacity, int totalStudents, int jets)
{
int remainingStudents;
remainingStudents = jetCapacity * jets;
return remainingStudents;
}
}

最佳答案

你这样调用calculateJets

jets = calculateJets(jetCapacity, totalStudents);

但是这个方法的参数名称暗示你已经在调用中调换了它们的顺序

public static int calculateJets(int totalStudents, int jetCapacity)

这意味着您实际上是在使用整数算法计算 155/3013,即 0

关于java - 方法返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9576040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com