最簡(jiǎn)單的java代碼肯定就是這個(gè)了,如下:
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為木蘭等服務(wù)建站,木蘭等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為木蘭企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個(gè)代碼了。如果是零基礎(chǔ)的新手朋友們可以來(lái)我們的java實(shí)驗(yàn)班試聽(tīng),有免費(fèi)的試聽(tīng)課程幫助學(xué)習(xí)java必備基礎(chǔ)知識(shí),有助教老師為零基礎(chǔ)的人提供個(gè)人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評(píng)團(tuán)進(jìn)行專(zhuān)業(yè)測(cè)試,幫助測(cè)評(píng)學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來(lái)報(bào)名體驗(yàn)實(shí)驗(yàn)班的新手快速入門(mén)java,更好的學(xué)習(xí)java!
package?com.lp.test;
public?class?StringTest?{
public?static?void?main(String[]?args)?{
//?TODO?code?application?logic?here
//打印main方法參數(shù)
if?(args.length??0)?{
for?(int?i?=?0;?i??args.length;?i++)?{
System.out.println(args[i]);
}
}?else?{
System.out.println("No?args.");
}
String?str?=?"12345";
//將str拆分為單個(gè)char輸出
for?(int?i?=?0;?i??str.length();?i++)?{
System.out.print(str.charAt(i)?+?"?");
}
System.out.println("");
//截取str前四位
str?=?str.substring(0,?4);
System.out.println(str);
//將截取后的str與"77777"進(jìn)行拼接
str?=?str.concat("77777");
System.out.println(str);
//輸出7在str中第一次出現(xiàn)的位置
int?index?=?str.indexOf('7');
System.out.println(index);
//獲取7在str中最后一次出現(xiàn)的位置
int?lastIndex?=?str.lastIndexOf('7');
System.out.println(lastIndex);
//將str中的7全部換為6
str?=?str.replace('7',?'6');
System.out.println(str);
//將str中第一次出現(xiàn)的"6666"置換為"5"
str?=?str.replaceAll("6666",?"5");
System.out.println(str);
//初始化一個(gè)包含"12345"的字符串緩沖對(duì)象
StringBuilder?strb?=?new?StringBuilder("12345");
//循環(huán)輸出字符串緩沖對(duì)象的內(nèi)容
for?(int?i?=?0;?i??strb.length();?i++)?{
System.out.print(strb.charAt(i)?+?"?");
}
System.out.println("");
//刪除strb中索引為4的字符
strb.deleteCharAt(4);
System.out.println(strb);
//在刪除字符后的strb中拼接"77777"
strb.append("77777");
System.out.println(strb);
//在索引為4芳容位置上插入"56";
strb.insert(4,?"56");
System.out.println(strb);
//顛倒strb中的字符順序
strb.reverse();
System.out.println(strb);
String?hello?=?"HelloWord";
//將hello字符串轉(zhuǎn)換為全小寫(xiě)
System.out.println(hello.toLowerCase());
//將hello字符串轉(zhuǎn)換為全大寫(xiě)
System.out.println(hello.toUpperCase());
}
}
//都是從新手過(guò)來(lái)的,以下代碼供參考
//1.
public?class?BankAccount?{
private?static?String?acctnum;
private?static?double?money;
private?static?void?showAcct()?{
System.out.println("賬號(hào)為:?"?+?acctnum);
}
private?static?void?showMoney()?{
System.out.println("余額為:?"?+?money);
}
public?BankAccount(String?acc,?double?m)?{
this.acctnum?=?acc;
this.money?=?m;
}
public?static?void?main(String[]?args)?{
BankAccount?ba?=?new?BankAccount("626600018888",?5000.00);
ba.showAcct();
ba.showMoney();
}
}
//2.
public?class?Triangle?{
private?static?float?a;
private?static?float?b;
private?static?float?c;
public?Triangle(float?a,?float?b,?float?c)?{
this.a?=?a;
this.b?=?b;
this.c?=?c;
}
public?static?boolean?judgeTriangle(float?a,?float?b,?float?c)?{
if?((a??Math.abs(b?-?c)??a??b?+?c)
?(b??Math.abs(a?-?c)??b??a?+?c)
?(c??Math.abs(a?-?b)??c??a?+?b))
return?true;
else
return?false;
}
public?float?getCircumference()?{
return?this.a?+?this.b?+?this.c;
}
}
//3.
public?class?TestTriangle?{
public?static?void?main(String[]?args)?{
Triangle?t?=?new?Triangle(5.3f,7.8f,9.3f);
if(t.judgeTriangle(5.3f,7.8f,9.3f)){
System.out.print("能夠成三角形,周長(zhǎng)為:?");
System.out.printf("%9.2f",t.getCircumference());}
else
System.out.println("不能構(gòu)成三角形");
}
}
public?class?Test{
public?static?String?output="?";
public?static?void?foo(int?i){
try{
if(i==1){
throw?new?Exception();//如果參數(shù)為1,拋出異常,進(jìn)入到catch
}
output+="1";
}catch(Exception?e){
output+="2";//如果參數(shù)為1,執(zhí)行這里
return;
}finally{
output+="3";//不管怎樣這里都要執(zhí)行
}
output+="4";//這里是最后一個(gè)執(zhí)行語(yǔ)句,拋出異常就不執(zhí)行這里
}
public?static?void?main(String[]?args){
foo(0);//第一次調(diào)用
foo(1);//第二次調(diào)用
System.out.println(Test.output);
}
}
/*
*?現(xiàn)在說(shuō)下執(zhí)行步驟:output的值我[]括起來(lái)
*?第一次調(diào)用foo(0):(1)參數(shù)為0,所以執(zhí)行output+="1",那么output現(xiàn)在為[?1];
*? ????(2)執(zhí)行到output+="3",那么output現(xiàn)在為[?13];
*? ????(3)執(zhí)行到output+="4";那么output現(xiàn)在為[?134]
*?第二次調(diào)用foo(1):(1)執(zhí)行if里面,拋出異常
*? ????(2)進(jìn)入到catch,執(zhí)行output+="2",output現(xiàn)在為[?1342]
*? ????(3)進(jìn)入finally,執(zhí)行output+="3", output現(xiàn)在為[?13423]
*/
分享名稱(chēng):java新手代碼大全翻譯 java新手代碼大全翻譯中文
網(wǎng)頁(yè)地址:http://jinyejixie.com/article22/hpdcjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、網(wǎng)站營(yíng)銷(xiāo)、建站公司、網(wǎng)站收錄、網(wǎng)站改版、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)