Java programming problems

來源:互聯網
上載者:User

標籤:ora   字元數組   定義   數組   char   sel   畫圓   選擇   設定   

1、使用迴圈把26個字母按字典順序存入數組,在不使用另外數組的情況下將其逆序存放,在根據處理後的字元數組建立一個字串並輸出

  public static void main(String[] args) {
        char a[]=new char[26],c;   //中間變數c
        int i;
        for(i=0;i<a.length-1;i++){
            a[i]=(char)(‘a‘+i);            
        }
        for(i=0;i<13;i++){
            c=a[i];
            a[i]=a[25-i];
            a[25-i]=c;    
        }
        String s=new String(a);
        System.out.println(s);
    }
}

2、設計一個動物介面,並設計相應的動作,如跑,跳,走。在設計一個狗類實現這個動物介面,該狗類具有一些基本屬性,如名稱,大小,體重等。編寫測試類別測試是

      否達到預定功能。要求使用自訂的包。

 

 3、定義兩個文字框,一個文字框用於提示輸入密碼,另一個是密碼框,以“*”代替輸入的密碼

  public class test2 extends Applet{    
          TextField  text1,text2;
          public void init(){
              text1=new TextField("請輸入密碼:",10);
              text1.setEditable(false);
              text2=new TextField(10);
              text2.setEchoChar(‘*‘);
                add(text1);
               add(text2);            
      }
  }

4、設定列表選擇模型為單選:list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION)

  設定列表選擇模型為多選:list.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)

5、編寫一個java  applet應用小程式,畫三個圓,顏色分別為紅黃綠

  public class test3  extends Applet {
       public void paint(Graphics g){
        g.setColor(Color.red);
        g.drawRoundRect(100, 100, 100, 100, 100, 100);
        g.drawString("紅色圓", 100, 100);
        
        g.setColor(Color.green);
        //g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
        //x,y表示座標,對於畫圓後面四個參數必須相等
        g.drawRoundRect(50, 50, 50, 50, 50, 50);
        g.fillRoundRect(40, 50, 50, 50, 50, 50);//畫圓填充色
        g.drawString("綠色圓", 50, 50);
    }
}

 

Java programming problems

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.