【问题标题】:Help with intro to Java procedure call帮助介绍 Java 过程调用
【发布时间】:2011-01-22 18:45:27
【问题描述】:

我有一个 Java 学校项目被分配执行以下任务:

编写一个应用程序以用于 大学招生办公室。成为 被这所学校录取的学生 必须有: •一个成绩点 平均3.0或更高和 入学分数 60 或更高 •An 85或更高的入学分数和任何 平均绩点 做事 更用户友好,写一些代码 对数据进行一些错误检查。
也就是说,如果平均绩点是 不在 0.0 和 4.0 之间,或者如果 入学分数不介于 0 和 100,然后打印适当的错误 屏幕消息告诉用户 他们输入了无效数据。采用 上面的标准写一个 过程调用,接受,需要 平均绩点和入学 score 作为参数并返回 no 价值。此过程将打印 “接受”或“拒绝”, 因此。最后写一个main 提示用户输入的过程 平均绩点和入学 分数。那么这个程序应该 调用接受的方法来显示 结果。

虽然我在没有仔细阅读说明的情况下愚蠢地编写了以下代码。我的问题是我不确定如何调用程序。另外我如何将变量传递给这个被调用的过程?任何帮助或其他示例都会有所帮助。下面是我编写的代码,它没有被调用的 Accept 过程。

import java.util.Scanner;
class College {

    public static void main(String[] args) {
         double testGPA;
         int testScore;

        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to Student Admisions");
        System.out.println("Please student prospects GPA: ");
        testGPA = input.nextDouble();

        System.out.println("Now enter prospect students Test Score: ");
        testScore = input.nextInt();
        System.out.println("-----------------------");

        if (testGPA >= 0.0 && testGPA <= 4.0 && testScore >= 0 && testScore <= 100){
            if(testGPA >= 3.0 && testScore >= 60 || testScore >= 85){
                System.out.println("Student is ACCEPTED to university!");
                System.out.println("Students GPA is a " + testGPA + " and students test score is a " + testScore + "%");
                }
            else {
                System.out.println("Student is NOT ACCEPTED to university!");
                System.out.println("Students GPA is a " + testGPA + " and students test score is a " + testScore + "%");
            }
        }
        else{
            System.out.println("Please Check GPA and Test score input!");
            System.out.println("Your inputs were:");
            System.out.println(testGPA + " = GPA should be between 0.0 and 4.0.");
            System.out.println(testScore + " = Test Score should be between 0 and 100");
        }
    }
}

【问题讨论】:

  • 我对要求您用 Java 编写“过程”(而不是方法,通常的术语)的作业有些怀疑,但如果您真的不知道如何声明方法使用参数,我会强烈建议 SO 不应该是你的起点。向您的老师寻求帮助,或从一开始就阅读 Java 书籍。

标签: java call procedure


【解决方案1】:

这里有一个非常简单的过程调用演示。

public class Demo {
    private static void prn(int x) {
        System.out.println(x);
    }
    public static void main(String[] args) {
        prn(2);
        prn(3);
    }
}

知道了吗?

【讨论】:

  • 你用大写 c 拼写了“class”
  • 我知道它确实有助于清除它。非常感谢。完成了我的程序,它现在运行良好!
猜你喜欢
  • 1970-01-01
  • 2016-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-21
  • 1970-01-01
  • 1970-01-01
  • 2011-05-14
相关资源
最近更新 更多