/*這個相當(dāng)詳細(xì)了.
10年積累的網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè)經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有瓊海免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
程序也不算太難.而且給老師看的時候效果比較好.因為有圖形化界面,又實現(xiàn)一個比較實用的功能.老師會比較高興的.
建立一個文件名為Change.java就可以編譯了*/
/*
* 這個程序?qū)崿F(xiàn)輸入身高算出標(biāo)準(zhǔn)體重,輸入體重,算出身高的功能
*/
import java.awt.*; //導(dǎo)入相關(guān)類包,這才樣使用相應(yīng)awt圖形界面的類
import java.awt.event.*;//同上
public class Change extends Frame { //定義一個類Change, 父類是Frame(圖形界面的)
Button b = new Button("互查"); //創(chuàng)建一個按鈕的對象b,顯示為"互查"
Label l1 = new Label("身高(cm)");//創(chuàng)建一個lable.顯示身高
Label l2 = new Label("體重(kg)");//創(chuàng)建一個lable 顯示體重
double heigth, weigth; //定義變量
double x, y; //定義變量
TextField tf1 = new TextField(null, 10);//添加Text框
TextField tf2 = new TextField(null, 10);//添加Text框
public Change() {//類的構(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();//自動放到窗口里排列上邊的組件
setVisible(true);//可以讓用戶看到窗口
addWindowListener(new WindowAdapter() {//如果按 X, 關(guān)閉窗口
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());//添加button監(jiān)聽函數(shù)
}
class ButtonListener implements ActionListener {//實現(xiàn)click button時功能操作
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(); //建立類Change的對象,并調(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("對家手中的牌是:||");
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);
}
}
}
最簡單的java代碼肯定就是這個了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個代碼了。如果是零基礎(chǔ)的新手朋友們可以來我們的java實驗班試聽,有免費的試聽課程幫助學(xué)習(xí)java必備基礎(chǔ)知識,有助教老師為零基礎(chǔ)的人提供個人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評團(tuán)進(jìn)行專業(yè)測試,幫助測評學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費幫助來報名體驗實驗班的新手快速入門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中沒有java.lang.Array這個類..所以cl=Class.forName("java.lang.Array");這句會報錯的...
但是catch(Exception e){}你的捕獲異常這什么都沒有做..
所以你看不到..于是cl還是為null..所以Field[] f=cl.getDeclaredFields();就會報異常了..
可以將java.lang.Array改為java.lang.String等等存在的類..
什么都不輸出是因為java.lang.reflect.Array這個類里面沒有任何屬性。。
你用java.lang.String試下就知道了哈。。
文章標(biāo)題:java最牛代碼 看懂java代碼
文章URL:http://m.rwnh.cn/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)容(圖片、視頻和文字)以用戶投稿、用戶轉(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)