猿问

搞不懂哪里出错了

一样的代码,下面怎么就不兼容呢?

public class Item {

    String name;

    int price;

     

    public static void main(String[] args) {

        Item potion = new Item();  

        potion.name= "血瓶";

        potion.price =50;

         

        Item shoe = new Item();

        shoe.name= "草鞋";

        shoe.price =300;

         

        Item sword = new Item();   

        sword.name= "长剑";

        sword.price =350;

         

    }

}

public class Item{

String name; //名字

int price; //价格

public static void main(String[]args){

Item xuepin = new  Item();

xuepin.name = "血瓶";

xuepin.price = "50";

Item caoxie = new  Item();

caoxie.name = "草鞋";

caoxie.price = 300;

Item changjian = new  Item();

changjian.name = "长剑";

changjian.price = "350";

}

}

 不兼容的类型: String无法转换为int

                xuepin.price = "50";

                               ^

Item.java:17: 错误: 不兼容的类型: String无法转换为int

                changjian.price = "350";


慕粉3305249
浏览 1439回答 3
3回答

慕斯6372754

数字的那些 双引号去掉

慕少7573967

···你自己打错了吧
随时随地看视频慕课网APP

相关分类

Java
我要回答