導航:首頁 > 編程語言 > 綠色編程的作業

綠色編程的作業

發布時間:2023-02-24 14:57:16

『壹』 Java編程作業,急用

以下是源代碼和運行結果截圖,如果哪裡有問題的話可以來找我。

classPet{

intage;

intweight;

publicPet(intage,intweight){

super();

this.age=age;

this.weight=weight;

}

publicvoidshowInfo(){

System.out.println("myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnthis.weight;

}

publicintgetAgeInfo(){

returnthis.age;

}

}

interfaceEatable{

publicabstractvoidbeEatted();//默認為public和abstract

}

classCatextendsPet{

publicCat(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maCat,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

}

{

publicDog(intage,intweight){

super(age,weight);

//TODOAuto-generatedconstructorstub

}

privateintcry;

publicvoidshowInfo(){

System.out.println("I'maDog,myweightis"+this.weight+"andmyageis"+this.age);

}

publicintgetWeightInfo(){

returnsuper.getWeightInfo();

}

publicintgetAgeInfo(){

returnsuper.getAgeInfo();

}

publicvoidbeEatted(){

}

}

classFruitimplementsEatable{

publicFruit(Stringcolor,Stringaddress){

super();

this.color=color;

this.address=address;

}

Stringcolor;

Stringaddress;

publicvoidbeEatted(){

System.out.println("I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("mycoloris"+this.color+"andmyaddressis"+this.address);

}

publicStringgetColorInfo(){

returnthis.color;

}

publicStringgetAddressInfo(){

returnthis.address;

}

}

classBananaextendsFruit{

publicBanana(Stringcolor,Stringaddress){

super(color,address);

//TODOAuto-generatedconstructorstub

}

publicvoidbeEatted(){

System.out.println("I'maBanana,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'maBanana,mycoloris"+this.color+"andmyaddressis"+this.address);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

classAppleextendsFruit{

Stringtype;

publicApple(Stringcolor,Stringaddress,Stringtype){

super(color,address);

this.type=type;

//TODOAuto-generatedconstructorstub

}

publicStringgetType(){

returntype;

}

publicvoidbeEatted(){

System.out.println("I'manapple,I'mbeeneaten!");

}

publicvoidshowInfo(){

System.out.println("I'manApple,mycoloris"+this.color+",myaddressis"+this.address

+"andmytypeis"+type);

}

@Override

publicStringgetColorInfo(){

//TODOAuto-generatedmethodstub

returnthis.getColorInfo();

}

@Override

publicStringgetAddressInfo(){

returnthis.getAddressInfo();

}

}

publicclassPrograms{

publicstaticvoidmain(String[]args){

Catmycat=newCat(10,20);

Dogmydog=newDog(10,24);

Bananamybanana=newBanana("黃色","北京");

Applemyapple=newApple("紅色","上海","新品種");

mycat.showInfo();

mydog.showInfo();

mybanana.showInfo();

myapple.showInfo();

mydog.beEatted();

mybanana.beEatted();

myapple.beEatted();

}

}

『貳』 編程作業怎麼做!

不知道你問的是哪一題

假設是其中最清楚的那一題,如555555最大的三位數

其實這題很簡單,如果不考慮性能的話,直接從100開始遍歷,定義兩個局部變數
假設是int a與int b
弄一個循環,a從100開始,然後b從1開始

a×b如果等於55555,就記錄在一個temp變數一面,如果遇到下一個a×b等於555555的組合,就跟temp比,如果比temp記錄的數大,就用大的替換掉temp裡面小的那一個。

如果a×b大於55555,立即結束本次循環,a+1,跳入下一次循環。

其實還有更簡便的方法。。。不過用到一些復雜的數學公式就不說了。

如果要簡單粗暴的話,直接開多線程去找,一個線程負責一個區間,比方說100-200,200-300一直到5555500到555555,找到滿足a×b=555555的數,而且每次a+5,(因為555555末尾是5,其中一個乘數必定是5,所以以5作為每次循環的步長應該能提升5倍性能)

總之怎麼簡單粗暴怎麼來。

『叄』 C++編程作業,怎麼寫

閱讀全文

與綠色編程的作業相關的資料

熱點內容
圖解政治pdf 瀏覽:162
自製可編程計算機 瀏覽:132
每個文件夾放入一張圖片 瀏覽:453
cgzip壓縮文件夾 瀏覽:591
如何找下載的app 瀏覽:470
程序員之死最新進展 瀏覽:261
台電u盤可以下載加密嗎 瀏覽:697
java培訓機構上海 瀏覽:616
長城伺服器怎麼裝機 瀏覽:355
pm和hm哪個軟體編程好 瀏覽:205
咋樣把文件夾強力去除 瀏覽:989
jvmgc演算法 瀏覽:599
我的世界怎樣控制命令方塊發文字 瀏覽:863
期貨翻番計演算法 瀏覽:495
華為底部app如何增加 瀏覽:115
為什麼用了幾個星期的安卓充電器就壞了 瀏覽:358
伺服器風扇響怎麼回事 瀏覽:16
django打包編譯 瀏覽:196
u盤加密碼視頻 瀏覽:165
cmake創建文件夾 瀏覽:935