數(shù)據(jù)加載中……

          StaticMothed.java

           /*
          *靜態(tài)方法訪問(wèn)實(shí)例字段及靜態(tài)字段
          */
          public class StaticMethod(){
          static int a=15;
          static int b=2;
          public static void main(String[] args)
          {
          System.out.println(a+"/"+b+"="+(a/b));
          }
          }

          posted @ 2008-10-21 18:38 郭興華 閱讀(90) | 評(píng)論 (0)編輯 收藏
          StudentTest.java

          /*
          *學(xué)生類,包括學(xué)生類的基本信息
          */
          public class StudentTest{
          public static void main(String[] args)
          {
          Student tom=new Student("Tom","20020410");
          tom.setStudentSex("man");
          tom.setStudentAddress("America");
          System.out.println(tom.toString());
          }
          }
          class Student{
          private String strName=";
          private String strNumber="";
          private String strSex="";
          private String strSpeciality="";
          private String strAddress="";
          public Student(String name,String number){
          strName=name;
          strNumber=number;
          }
          public String getStudentName(){
          return strName;
          }
          public String getStudentNumber(){
          return strNumber;
          }
          public String getStudentSex(){
          return strStudentSex;
          }
          public String setStudentSex(String sex)
          {
          strSex=sex;
          }
          public String getStudentBirthday(){
          return strBirthday;
          }
          public void setStudentBirthday(String birthday){
          strBirthday=birthday;
          }
          public String getStudentSpeciality()
          {
          return strSpeciality;
          }
          public void setStudentSpeciality(){
          strSpeciality=speciality;
          }
          public String getStudentAddress(){
          return strAddress;
          }
          public void setStudentAddress(String address){
          strAddress=address;
          }
          public String toString(){
          String information ="student name="+strName+",student number ="+strNumber;
          if(!strSex.equals(""))
          information+=",sex="+strSex;
          if(!strBirthday.equals(""))
          information+=",birthday ="+strBirthday;
          if(!strAddress.equals(""))
          information+=",address="+strAddress;
          return information;
          }

          }

          }

          posted @ 2008-10-21 18:16 郭興華 閱讀(218) | 評(píng)論 (0)編輯 收藏
          StudentOverloading.java

          /*
          *學(xué)生類的重載
          */
          public class StudentOverloading{
          public static void main(String[] args){
          Student tom=new Student("Tom");
          }}

          /*
          *學(xué)生類,包括學(xué)生的基本信息
          */
          public static void main(String[] args){
          S}
          class Student{
          private String strName="";
          private String strNumber="";
          private String strSex="";
          private String strBirthday="";
          private String strSpciality="";
          private String strAddress="";
          public Student(String name,Stirng number){
          strName=name;
          StrNumber=number;}
          public String getStudentName(){
          return strName;
          }
          public String getStudentNumber(){
          return strNumber;
          }
          public String setStudentSex(String sex){
          srtSex=sex;
          }
          public String getStudentSex(){
          return strSex;
          }
          public String getStudentBirthday(){
          return strBirthday;
          }
          public void setStudentBirthday(String birthday){
          strBirthday=birthday;}
          public String getStudentSpeciality(){
          teturn strSpeciality;
          }
          public void setStudentSpeciality(String speciality){
          strSpeciality=speciality;
          }
          public String getStudentAddress(){
          return strAddress;
          }
          public void set}

          posted @ 2008-10-20 14:33 郭興華 閱讀(91) | 評(píng)論 (0)編輯 收藏
          StaticMethod.java

          /*
          *靜態(tài)方法訪問(wèn)實(shí)例字段及靜態(tài)字段
          */
          public class StaticMethod{
          static int a=15;
          static int b=2;
          public static void main(String[] args){
          System.out.println(a+"/"+b+"="+(a/b));
          }}

          posted @ 2008-10-20 13:51 郭興華 閱讀(67) | 評(píng)論 (0)編輯 收藏
          MathTest.java

          /*
          *Math類數(shù)學(xué)函數(shù)的運(yùn)用,由于Math類中的方法全部是靜態(tài)的,所以可以直接利用類名調(diào)用
          */
          public class MathTest{
          public static void main(String[] args){
          double x=4.51;
          System.out.println(Math.sqrt(x));
          System.out.println(Math.round(x));
          }}

          posted @ 2008-10-20 13:44 郭興華 閱讀(91) | 評(píng)論 (0)編輯 收藏
          InstanceTest.java

          /*
          *訪問(wèn)同名的實(shí)例字段 和局部變量
          */
          public class InstanceTest{
          private int a=10;
          public static void main(String[] args){
          new InstanceTest().print();
          }
          public void print(){
          int a =15;
          int b=10;
          if(b==10){
          System.out.println("局部變量 a="+a);
          System.out.println("實(shí)例字段變量a ="+this.a);
          }
          }
          }

          posted @ 2008-10-20 13:39 郭興華 閱讀(76) | 評(píng)論 (0)編輯 收藏
          InitObject.java

          /*
          *對(duì)象變量的初始化
          */
          import java.util.Date;
          public class InitObject{
          private Date today;//構(gòu)建一個(gè)對(duì)象變量
          public static void main(String[] args){
          new InitObject().print();
          }
          public void print(){
          System.out.println(today.toString());
          }
          }

          posted @ 2008-10-20 13:34 郭興華 閱讀(145) | 評(píng)論 (0)編輯 收藏
          ImportTest.java

          /*
          *包名的引用
          */
          import java.util.Date;
          public class ImportTest{
          public static void main(String[] args){
          System.out.println(new Date());
          }}

          posted @ 2008-10-20 13:29 郭興華 閱讀(59) | 評(píng)論 (0)編輯 收藏
          FormateDateOutput.java

          /*
          *日歷按照格式輸出
          */
          import java.util.Calendar;
          import java.swing.JOptionPane;
          import java.text.SimpleDateFormat;
          public class FormatDateOutput{
          private int year;
          public static void main(String[] args){
          String input=JOptionPane.showInputDialog("請(qǐng)輸入有效的年分(YYYY):");
          int year1=Integer.parseInt(input);//將字符串轉(zhuǎn)化為整數(shù)
          FormateDateOutput out=new FormateDateOutput();
          out.setYear(year1);
          if(year1!=0&&input.length()==4)
          {
          out.FormateDateStr();
          }else{
          System.out.println("輸入的年份無(wú)效。");
          }System.exit(0);}
          public void FormateDateStr(){
          SimpleDateFormat formatter=(SimpleDateFormat)SimpleDateFormat.getDateInstance();
          formatter.applyPattern("yyyy-MM-dd");
          Calendar cal=Calendar.getInstance();
          for(int i=0;i<12;i++){
          cal.set(year,i,1);
          int temp=cal.getActualMaxmum(Calendar.DAY_OF_MONTH);
          for (int j=1;j<=temp;j++){
          cal.set(year,i,j);
          String str=formatter.format(cal.getTime());
          System.out.println("當(dāng)前的時(shí)間是:"+str);}}}
          public void setYear(int year){
          this.year=year;
          System.out.println("the year is "+this.year);
          }
          public int getYear(){
          return year;}}

          posted @ 2008-10-20 13:24 郭興華 閱讀(90) | 評(píng)論 (0)編輯 收藏
          CalendarTest.java

          /*
          *GregroianCalendar類的設(shè)置器與訪問(wèn)器
          */
          import java.util.*;
          public class CalendarTest{
          public static void main(String[] args){
          new CalendarTest().print();
          }
          public void print(){
          Calendar calendar=new GregorianCalendar();
          Date TrialTime=new Date();
          Calendar.setTime(trialtTime);
          System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
          System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
          System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
          System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
          System.out.println("DATE: "+ calendar.get(Calendar.DATE));
          System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
          System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
          System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
          System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
          System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
          System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
          System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
          System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
          System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
          System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
          System.out.println("Current Time, with hour reset to 3");
          calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
          calendar.set(Calendar.HOUR, 3);
          System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
          System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
          System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
          System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
          System.out.println("DATE: " + calendar.get(Calendar.DATE));
          System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
          System.out.println("DAY_OF_YEAR: "+ calendar.get(Calendar.DAY_OF_YEAR));
          System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
          System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
          System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
          System.out.println("HOUR: "+ calendar.get(Calendar.HOUR));
          System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
          System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
          System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
          System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); }}

          posted @ 2008-10-20 13:01 郭興華 閱讀(251) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題
          共9頁(yè): 上一頁(yè) 1 2 3 4 5 6 7 8 9 下一頁(yè) 
          主站蜘蛛池模板: 山东| 南郑县| 宝兴县| 南岸区| 工布江达县| 新野县| 定远县| 静海县| 合江县| 土默特右旗| 德保县| 凤阳县| 平舆县| 游戏| 永康市| 从江县| 康定县| 封丘县| 平舆县| 应城市| 驻马店市| 萨迦县| 黄骅市| 宕昌县| 乡宁县| 葵青区| 山丹县| 齐河县| 黄山市| 平罗县| 高密市| 乌拉特前旗| 大丰市| 凌源市| 雷波县| 阜城县| 奉贤区| 丰都县| 新河县| 遂昌县| 墨竹工卡县|