如何让我的代码写入通过或失败 [英] How Do I Make My Code Write Pass Or Fail
问题描述
public class Exercises01 {
public static void main(String [] args){
{
System.out.println(测试:调用checkPassFail()...);
checkPassFail();
System.out.println(上面有应写成'FAIL');
System.out.println();
}
}
public static void checkPassFail(){
int mark = 20;
if(mark => 50){
System.out。的println( PASS);
} else {
System.out.println(FAIL);
}
}
}
public class Exercises01 {
public static void main(String[] args){
{
System.out.println("Test: call to checkPassFail()...");
checkPassFail();
System.out.println("above there should be written 'FAIL'");
System.out.println();
}
}
public static void checkPassFail(){
int mark = 20;
if (mark => 50){
System.out.println("PASS");
}else{
System.out.println("FAIL");
}
}
}
推荐答案
首先需要修改代码以便编译:
You first need to fix the code so it compiles:
if (mark => 50){ // ERROR
// should be
if (mark >= 50){ // Greater Than or Equal
就目前而言,您的代码甚至无法编译。我建议你阅读 Java
编程语言的教程。
As it stands, your code wouldn't even compile. I suggest you reading a tutorial on Java
programming language.
不要使用标记的固定值
- 目前它只打印FAIL,因为20< 50
我建议从用户或文件中获取值,并将其传递给checkPassFail
作为参数。
Don't use a fixed value formark
- at the moment it only ever prints FAIL because 20 < 50
I'd suggest getting a value from the user or a file, and passing it to thecheckPassFail
function as a parameter.
这篇关于如何让我的代码写入通过或失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!