大佬教程收集整理的这篇文章主要介绍了有人可以帮助我使用此代码,它没有返回我想要的结果,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都可以编译此代码并帮助我,因为它没有返回我想要的结果。我不知道是返回不起作用还是什么,请帮助我,代码如下:
public class ComputeAverage {
public static voID main (String[] args) {
new ComputeAverage().computeAverage(4);
}
public double computeAverage(int how_many)
{ double @R_549_10586@l_points = 0.0; // the @R_549_10586@l of all test scores
int count = 0; // the quantity of tests read so far
while ( count != how_many )
// at each iteration: @R_549_10586@l_points == exam_1 + exam_2 + ... + exam_count
{ // ask the user for the next exam score:
String input = JOptionPane.showinputDialog("Type next exam score:");
int score = new Integer(input).intValue();
if (score < 0) {
JOptionPane.showmessageDialog(null,"Enter a positive numer");
@R_549_10586@l_points = @R_549_10586@l_points - score;
}
// add it to the @R_549_10586@l:
@R_549_10586@l_points = @R_549_10586@l_points + score;
count = count + 1;
// print a sumMary of the progress:
System.out.println("count = " + count + "; @R_549_10586@l = " + @R_549_10586@l_points);
}
// at conclusion: @R_549_10586@l_points == exam_1 + exam_2 + ... + exam_how_many
return (@R_549_10586@l_points / how_many);
}
}
您正在将值返回给 main,但没有在任何地方打印它。您可以使用摆动中的警报框来显示结果。
在 main 函数中而不是 .,
public static void main (String[] args) {
new ComputeAverage().computeAverage(4);
}
试试:
public static void main (String[] args) {
JOptionPane.showmessageDialog(null,"Exam score : " + new ComputeAverage().computeAverage(4));
}
以上是大佬教程为你收集整理的有人可以帮助我使用此代码,它没有返回我想要的结果全部内容,希望文章能够帮你解决有人可以帮助我使用此代码,它没有返回我想要的结果所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。