2017-07-04 48 views
-7
class Smartphone 
    { 
     private float screensize; 
     private float androidversion; 
     private int ram; 
     private int memory; 
     private int processor; 
     private String brand; 
//I also created String brand variable...at the rite position 
    public void setData(String brand,int screensize,int ram,int memory,int processor,float androidversion) 
    { 
     this.screensize=screensize; 
     this.androidversion=androidversion; 
     this.ram=ram; 
     this.memory=memory; 
     this.processor=processor; 
     this.brand=brand; 
    } 
    public void dispData() 
    { 
     System.out.println("the brand of the mobile is "+brand+"Smartphones"); 
     System.out.println("the screensize of the mobile is "+screensize+"inches"); 
     System.out.println("the ram of the mobile is "+ram); 
     System.out.println("the memory of the mobile is "+memory+"GB"); 
     System.out.println("the processor of the mobile is "+processor+"Ghz"); 
     System.out.println("the androidversion of the mobile is "+androidversion); 
    } 
    } 
    class App 
    { 
     public static void main(String args[]) 
     { 
      Smartphone xiaomi=new Smartphone(); 
//Error is causing here...the xiaomi string is not passing.. 
      xiaomi.setData("Xiaomi",5.5,3,32,2.6,8.0); 
     } 
    } 
+4

看看下一個參數。你試圖爲int參數傳遞一個double。 –

+0

是你的Locale中的一個整數? –

+0

是的,它是整數....我改變它漂浮...謝謝btw –

回答

1

你已經通過無效parameters.you可以通過固定的發送參數,如修復:

xiaomi.setData("Xiaomi",5.5f,3,32,2,8.0f); 

或更改函數簽名

String brand,float screensize,int ram,int memory,double processor,float androidversion 

並且還將變量更改爲 私人浮動屏幕尺寸;

private float androidversion; 
private int ram; 
private int memory; 
private double processor; 
private String brand; 
相關問題