第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在java中添加UnsignedInteger并繼續(xù)獲得預期的方法調用

在java中添加UnsignedInteger并繼續(xù)獲得預期的方法調用

慕田峪9158850 2021-11-17 17:22:57
我不斷收到方法調用預期錯誤。我不知道我能做什么。有沒有人知道我們如何在不改變它的情況下進行主要運行?嘗試了幾個小時不同的方法,但無法弄清楚。public class UnsignedInteger {  public static void main(String[] args){    UnsignedInteger three = new UnsignedInteger(3); // 3 is "autoboxed"    UnsignedInteger four = new UnsignedInteger(4); // 4 is "autoboxed"    UnsignedInteger sum = three.add(four);    System.out.println(sum); // Should print 7    try    {        UnsignedInteger broken = new UnsignedInteger(-1);    }    catch(IllegalArgumentException e)    {        System.out.println("Negative values are not allowed");     }int val;// This is the constructor. It should throw an IllegalArgumentException if a //negative value is passed inpublic UnsignedInteger(Integer value){   if(value<0){      throw new IllegalArgumentException("You have entered a negative number.");    val=value;   }}// This method will return the Integer that was passed in via the constructor.public Integer getRawInteger(){    return val;}// Return the sum of the value stored in this object with the object passed as a parameter (i.e., otherUint)// This should not mutate the state of our class.public UnsignedInteger add(UnsignedInteger otherUint){   return  getRawInteger(this.add(getRawInteger()));    }}
查看完整描述

1 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

public UnsignedInteger(Integer value) 是一個構造函數(shù),但您試圖在此處將其作為方法調用:

return UnsignedInteger(getRawInteger());

和這里:

return UnsignedInteger();

要調用構造函數(shù),您應該編寫:

return new UnsignedInteger();

此外,public UnsignedInteger(Integer value)構造函數(shù)不應該有 return 語句,因為構造函數(shù)不返回值。

此外,getRawInteger應該返回一個Integer,但您返回的是一個UnsignedInteger。


查看完整回答
反對 回復 2021-11-17
  • 1 回答
  • 0 關注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號