import java.util.*;
public class GoalsErrors
{
public static void main(String [] args)
{
int goals,errors;
System.out.println("Enter two number:");
Scanner keyboard = new Scanner(System.in);
goals = keyboard.nextInt();
errors = keyboard.nextInt();
if ((goals > 10) || (errors=0))
System.out.println("Wow!");
else
System.out.println("Oh well");
}
}cmd提示||不能应用于boolean,int我的原意是想goals>10,且errors=0时,输出“wow!”,否则,输出“oh well”怎么改嘎?这是《java程序设计与问题解决基础篇》上的题
public class GoalsErrors
{
public static void main(String [] args)
{
int goals,errors;
System.out.println("Enter two number:");
Scanner keyboard = new Scanner(System.in);
goals = keyboard.nextInt();
errors = keyboard.nextInt();
if ((goals > 10) || (errors=0))
System.out.println("Wow!");
else
System.out.println("Oh well");
}
}
你这是赋值
改成errors==0
应该是:if ((goals > 10) || (errors==0))
少了个等号的
应该这样写吧:if ((goals > 10) && (errors==0))
public class GoalsErrors
{
public static void main(String [] args)
{
int goals,errors;
System.out.println("Enter two number:");
Scanner keyboard = new Scanner(System.in);
goals = keyboard.nextInt();
errors = keyboard.nextInt();
if ((goals > 10) || (errors=0)) 这错了(errors=0)应该为(errors==0)
System.out.println("Wow!");
else
System.out.println("Oh well");
}
}
你是说要 goals>10,且errors=0时,输出“wow!”,否则,输出“oh well”
那应该是if(goals>10 && errors == 0){
System.out.println("Wow!");
}else{
System.out.println("Oh well");
}
应该用&&符号吧?而且 errors 应该是==号
不细心呀