快捷导航

这个是错哪了?

package com.imooc;import java.util.Scanner;public class match {        public static void main(String[] args) {                                Scanner input=new Scanner(System.in);                System.out.println("Please input the score:");                int score=input.nextInt();                System.out.println("Please input the sex:");                String sex=input.next();                //int score=99;                if(score>80) {                        if(sex=="m")                                System.out.println("Enter the man's final!");                        else                                System.out.println("Enter the woman's fanal!");                }                else {                        System.out.println("out!");                }        }}

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

这里应该sex.equals("m")这样写,而不是sex=="m"。字符串比较,equals是比较内容是否相等,==是比较两个引用是否相等。
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP