/*這個(gè)相當(dāng)詳細(xì)了.

10年積累的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶(hù)對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶(hù)得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有瓊海免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
程序也不算太難.而且給老師看的時(shí)候效果比較好.因?yàn)橛袌D形化界面,又實(shí)現(xiàn)一個(gè)比較實(shí)用的功能.老師會(huì)比較高興的.
建立一個(gè)文件名為Change.java就可以編譯了*/
/*
* 這個(gè)程序?qū)崿F(xiàn)輸入身高算出標(biāo)準(zhǔn)體重,輸入體重,算出身高的功能
*/
import java.awt.*; //導(dǎo)入相關(guān)類(lèi)包,這才樣使用相應(yīng)awt圖形界面的類(lèi)
import java.awt.event.*;//同上
public class Change extends Frame { //定義一個(gè)類(lèi)Change, 父類(lèi)是Frame(圖形界面的)
Button b = new Button("互查"); //創(chuàng)建一個(gè)按鈕的對(duì)象b,顯示為"互查"
Label l1 = new Label("身高(cm)");//創(chuàng)建一個(gè)lable.顯示身高
Label l2 = new Label("體重(kg)");//創(chuàng)建一個(gè)lable 顯示體重
double heigth, weigth; //定義變量
double x, y; //定義變量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框
public Change() {//類(lèi)的構(gòu)造函數(shù),完成初始化
super("互查表");//創(chuàng)建窗口,標(biāo)題為互查表
setLayout(new FlowLayout(FlowLayout.LEFT));//設(shè)置布局
add(l1);//把lable 身高放到window里
add(tf1);//把Text 框 放到窗口上
add(l2); //把lable 體重放到window里
add(tf2);//Test放到窗口里
add(b);//把button放到窗口上
pack();//自動(dòng)放到窗口里排列上邊的組件
setVisible(true);//可以讓用戶(hù)看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 關(guān)閉窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button監(jiān)聽(tīng)函數(shù)
}
class ButtonListener implements ActionListener {//實(shí)現(xiàn)click button時(shí)功能操作
public void actionPerformed(ActionEvent e) {//當(dāng)click調(diào)用
if (tf1.getText()!=null) {//檢查tf1 test 是否為空
try {//取異常
x = Double.parseDouble(tf1.getText());//字符轉(zhuǎn)為double型
weigth = (x - 100) * 0.9;//算重量
tf2.setText("" + weigth);//顯示重量
} catch (NumberFormatException ex) {
tf1.setText("");//如果輸入不是數(shù)字,設(shè)為空
}
}
if (tf1.getText().equals("")==true){//tf1是否為空
y = Double.parseDouble(tf2.getText());//把tf2里的文本轉(zhuǎn)為double 型 的
heigth = y / 0.9 + 100; //算身高根據(jù)重量
tf1.setText("" + heigth);}//顯示身高
}
}
public static void main(String[] args) {//主函數(shù),程序入口
new Change(); //建立類(lèi)Change的對(duì)象,并調(diào)用他的構(gòu)造函數(shù)Change().顯示窗口
}
}
300行能干啥啊,你還不如自己做做練習(xí)題。
package suoha;
import java.util.ArrayList;import java.util.Random;
public class MainFunction {
private ArrayListMyCard cards = new ArrayListMyCard();
private int[] cardNumArr = new int[52];
private int[] mycards = new int[5];
private int[] p1cards = new int[5];
public static void main(String[] args) {
MainFunction mainfunc = new MainFunction();
mainfunc.makeCards();
mainfunc.cardNumArr = mainfunc.shuffleCards(mainfunc.cardNumArr);
mainfunc.catchCards();
mainfunc.showAllCardsOfHand();
//mainfunc.printNums();
}
/**
* 洗牌
* @param cardNums
* @return
*/
private int[] shuffleCards(int[] cardNums){
int size = cardNums.length;
int[] returnNums = new int[size];
//System.out.println(cardNums[0]+"=========================");
Random rand = new Random();
for(int i=size-1;i0;i--){
int nextInt = rand.nextInt(i);
returnNums[size-1-i] = cardNums[nextInt];
cardNums[nextInt] = cardNums[i];
cardNums[i] = returnNums[size-1-i];
//System.out.println("suijishu:"+nextInt+"||zhi:"+returnNums[size-1-i]);
}
returnNums[size-1] = cardNums[0];
return returnNums;
}
/**
* 抓牌
*/
private void catchCards(){
for(int i=0;i5;i++){
mycards[i] = cardNumArr[2*i];
p1cards[i] = cardNumArr[2*i+1];
}
}
private void showAllCardsOfHand(){
System.out.print("你手中的牌是:||");
for(int i=0;i5;i++){
MyCard myCard = cards.get(mycards[i]-1);
System.out.print(myCard.toString()+"||");
}
System.out.println();
System.out.print("對(duì)家手中的牌是:||");
for(int i=0;i5;i++){
MyCard myCard = cards.get(p1cards[i]-1);
System.out.print(myCard.toString()+"||");
}
}
/**
* 顯示牌的順序
*/
private void printNums(){
for(int i=0;icardNumArr.length;i++){
System.out.print(cardNumArr[i]+",");
}
}
/**
* 制作卡片
*/
private void makeCards(){
for(int i=1;i=13;i++){
for(int j=1;j=4;j++){
//System.out.println((i-1)*4+j);
MyCard card = new MyCard((i-1)*4+j, j, i);
cardNumArr[(i-1)*4+j-1] = (i-1)*4+j;
cards.add(card);
}
// MyCard card1 = new MyCard((i-1)*4+1, 1, i);
// MyCard card2 = new MyCard((i-1)*4+2, 2, i);
// MyCard card3 = new MyCard((i-1)*4+3, 3, i);
// MyCard card4 = new MyCard((i-1)*4+4, 4, i);
// cards.add(card1);
// cards.add(card2);
// cards.add(card3);
// cards.add(card4);
}
}
}
最簡(jiǎn)單的java代碼肯定就是這個(gè)了,如下:
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!
Class cl=null;
try{
cl=Class.forName("java.lang.Array");
}catch(Exception e){}
System.out.print("1231321wdfs");
Field[] f=cl.getDeclaredFields();
java中沒(méi)有java.lang.Array這個(gè)類(lèi)..所以cl=Class.forName("java.lang.Array");這句會(huì)報(bào)錯(cuò)的...
但是catch(Exception e){}你的捕獲異常這什么都沒(méi)有做..
所以你看不到..于是cl還是為null..所以Field[] f=cl.getDeclaredFields();就會(huì)報(bào)異常了..
可以將java.lang.Array改為java.lang.String等等存在的類(lèi)..
什么都不輸出是因?yàn)閖ava.lang.reflect.Array這個(gè)類(lèi)里面沒(méi)有任何屬性。。
你用java.lang.String試下就知道了哈。。
文章標(biāo)題:java最牛代碼 看懂java代碼
文章URL:http://chinadenli.net/article40/doopdeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、Google、做網(wǎng)站、電子商務(wù)、、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(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)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)