1.編碼之前想一想
創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)網(wǎng)站建設(shè)與網(wǎng)站營銷,提供網(wǎng)站制作、成都網(wǎng)站制作、網(wǎng)站開發(fā)、seo優(yōu)化、網(wǎng)站排名、互聯(lián)網(wǎng)營銷、小程序制作、公眾號商城、等建站開發(fā),創(chuàng)新互聯(lián)網(wǎng)站建設(shè)策劃專家,為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制解決方案,幫助客戶在新的全球化互聯(lián)網(wǎng)環(huán)境中保持優(yōu)勢。
用10分鐘,20分鐘甚至30分鐘的時間來想想你需要什么,想想什么樣的設(shè)計模式適合你將要編碼的東西。你會很慶幸“浪費”了那幾分鐘,當(dāng)你不得不更改或添加?xùn)|西到代碼中時你就不將將浪費幾分鐘而是要花費更多的時間。
2.注釋你的代碼
說真的,沒有什么比兩個月后檢查自己的代碼,卻不記得它用來干什么更糟糕的了。注釋所有重要的內(nèi)容,當(dāng)然那些顯而易見的就免了吧。
3.寫干凈的代碼
錯落有致。使用空格。根據(jù)功能模塊化你的代碼。閱讀RobertC.Martin寫的《CleanCode》,非常有幫助。此外,遵循代碼約定/標準(如,尤其如果是共享的代碼。
4.重構(gòu)
沒有人喜歡用那些超級長的方法。這通常(幾乎總是)意味著你混雜了功能。用更易于管理的方法分離代碼。還能使得代碼更可重用。
5.不要復(fù)制粘貼代碼
如果你有兩個或兩個以上相同的代碼塊,那么你可能做錯了什么。閱讀第4條。
6.使用有意義的名稱
雖然命名int變量為“elligent”或char為“mander”是很好笑;但是,這樣的名稱并不能說明變量是用來做什么的。
7.測試代碼
測試,測試,測試,還是測試。測試你的代碼。不要等到已經(jīng)做完程序之后再來測試,否則當(dāng)你發(fā)現(xiàn)一個巨大的bug,卻不知道它來自于哪里來的時候,你會追悔莫及。
自動化測試通常都是有價值的。它還有助于節(jié)省大量重測試和回歸測試的時間。
華為的愛心代碼是:
1、打開要發(fā)送的好友聊天窗,點擊表情符號。
2、找到擁抱和玫瑰的表情位置。
3、分別按順序輸入13個擁抱、4個玫瑰、2個擁抱、4個玫瑰、1個擁抱、24個玫瑰、1個擁抱、10個玫瑰、3個擁抱、8個玫瑰、5個擁抱、6個玫瑰、7個擁抱、4個玫瑰、9個擁抱、2個玫瑰、17個擁抱,然后發(fā)送。
4、最后發(fā)送出去就看到用擁抱和玫瑰的表情發(fā)出心形了
代碼如下,隨便附一句,一定要看寫的源碼,我已經(jīng)盡量馬馬虎虎的寫了,你更容易看懂。
public?class?Test?{
//?第八題
public?static?final?int?NUM?=?100;
public?static?final?double?GOOD?=?99.99;
public?static?final?String?CLASSNAME?=?"Test.Class";
public?static?final?long?MAX?=?9999999;
public?static?void?main(String[]?args)?{
//?第一題
byte?byte1?=?1;
short?short1?=?1;
int?int1?=?1;
long?long1?=?1;
float?float1?=?1;
double?double1?=?1.0;
System.out.println("byte1?-?"?+?byte1);
System.out.println("short1?-?"?+?short1);
System.out.println("int1?-?"?+?int1);
System.out.println("long1?-?"?+?long1);
System.out.println("float1?-?"?+?float1);
System.out.println("double1?-?"?+?double1);
//?第二題
String?name;
char?sex;
int?age;
boolean?isMember;
//?第三題
int?score1;
double?score2?=?98.5;
//?第四題
double?f1?=?10.1,?f2?=?34.2;
System.out.println("f1,f2的和:"?+?(f1?+?f2));
System.out.println("f1,f2的差:"?+?(f1?-?f2));
System.out.println("f1,f2的積:"?+?(f1?*?f2));
System.out.println("f1,f2的商:"?+?(f1?/?f2));
//?第五題
int?f3?=?5;
double?f4?=?45.6;
System.out.println("f3,f4的和:"?+?(f3?+?f4));
System.out.println("f3,f4的差:"?+?(f3?-?f4));
System.out.println("f3,f4的積:"?+?(f3?*?f4));
System.out.println("f3,f4的商:"?+?(f3?/?f4));
//?第六題
int?A?=?65;
char?a?=?(char)?A;
System.out.println("整型互轉(zhuǎn)char:"?+?a);
//?第七題
double?timor?=?123.456789;
int?x?=?Integer
.parseInt(new?java.text.DecimalFormat("0").format(timor));//?四舍五入
System.out.println("double?-?int?:"?+?x);
//?第八題(定義在最開始)
System.out.println("常量NUM的值:?"?+?NUM);
System.out.println("常量GOOD的值:?"?+?GOOD);
System.out.println("常量CLASSNAME的值:?"?+?CLASSNAME);
System.out.println("常量MAX的值:?"?+?MAX);
//?第九題(自定義商品類)
class?Goods?{
private?String?name;
private?double?price;
private?int?count;
private?double?total;
public?Goods(String?name,?double?price,?int?count)?{
this.name?=?name;
this.price?=?price;
this.count?=?count;
}
public?void?print()?{
total?=?price?*?count;
System.out.println("商品名 ??價格??????數(shù)量 ?總價");
System.out.println(name?+?" ?"?+?price?+?" ?"?+?count?+?" ?"
+?total);
}
}
Goods?goods?=?new?Goods("蘋果",?2,?10);
goods.print();
//?第十題
double?pi?=?3.14,?r,?d;
r?=?4;
d?=?2?*?r;
System.out.println("圓的周長:?"?+?(pi?*?d));
System.out.println("圓的面積:?"?+?(pi?*?r?*?r));
//?第十一題
String?qqname?=?"1234567890";
String?qqpassword?=?"asd!#@#$%66";
Date?birth?=?new?Date(2014,?5,?1);
boolean?isVIP?=?false;
char?sex1?=?'男';
StringBuilder?personInfo?=?new?StringBuilder();
personInfo.append("我是一個快樂的騷年");
personInfo
.append("然后a!#$%^*asdasdasdasdsa9d87a9s8d79asdjidauisdhausdihiasd");
//?第十二題
class?Swaper?{
public?void?change(int?num1,?int?num2)?{
int?temp?=?num1;
num1?=?num2;
num2?=?temp;
System.out.printf("a=%d,b=%d\n",?num1,?num2);
}
}
int?a1?=?2;
int?b1?=?5;
Swaper?swaper?=?new?Swaper();
swaper.change(a1,?b1);
}
}
程序員的表白代碼
第一條語言:Java代碼翻譯:直到死之前,每天愛你多一點代碼:while(lifeend){love++;}
第二條語言:C語言代碼翻譯:IcannotsayHellototheWorldwithoutu.代碼:#incldestdio.hintmain(){printf(HelloWorldn);retrn0;}//IcannotsayHellototheWorldwithoutu.
第三條語言:python代碼翻譯:山無陵,江水為竭,冬雷震震,夏雨雪,天地合,乃敢與君絕!代碼:if(mountain.arris==None):if(river.water==None):if(winter.thunder==True):if(summer.snow==True):if(sky.height==ground.height):i.withyou=Falseelse:i.withyou=True.
第四條語言:Erlang代碼代碼翻譯:深圳相遇,至死不渝代碼:-module(you_and_me).-export([start/1]).-record(person,{name,address,status}).start(Name)-one_world(Name).one_world(Name)keep_to_love_you(Person).say_goodbye(Person)-io:format(~p:seeyounextworld!~n,[Person#person.name]).see_you_next_world(Name)-one_world(Name).
第五條語言:Java語言代碼翻譯:愛你到天荒地老代碼:while(!world.destroy){System.out.println(iloveyou);}
分享題目:程序員愛心代碼java 用程序畫一個愛心代碼
文章路徑:http://vcdvsql.cn/article26/hepojg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站制作、動態(tài)網(wǎng)站、App開發(fā)、ChatGPT、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)