java技术博客

jsp博客
数据加载中……

StaticMothed.java

 /*
*静态方法访问实例字段及静态字段
*/
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 郭兴华 阅读(87) | 评论 (0)编辑 收藏
StudentTest.java

/*
*学生类,包括学生类的基本信息
*/
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 郭兴华 阅读(214) | 评论 (0)编辑 收藏
StudentOverloading.java

/*
*学生类的重载
*/
public class StudentOverloading{
public static void main(String[] args){
Student tom=new Student("Tom");
}}

/*
*学生类,包括学生的基本信息
*/
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 郭兴华 阅读(89) | 评论 (0)编辑 收藏
StaticMethod.java

/*
*静态方法访问实例字段及静态字段
*/
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 郭兴华 阅读(64) | 评论 (0)编辑 收藏
MathTest.java

/*
*Math类数学函数的运用,由于Math类中的方法全部是静态的,所以可以直接利用类名调用
*/
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 郭兴华 阅读(89) | 评论 (0)编辑 收藏
InstanceTest.java

/*
*访问同名的实例字段 和局部变量
*/
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("实例字段变量a ="+this.a);
}
}
}

posted @ 2008-10-20 13:39 郭兴华 阅读(73) | 评论 (0)编辑 收藏
InitObject.java

/*
*对象变量的初始化
*/
import java.util.Date;
public class InitObject{
private Date today;//构建一个对象变量
public static void main(String[] args){
new InitObject().print();
}
public void print(){
System.out.println(today.toString());
}
}

posted @ 2008-10-20 13:34 郭兴华 阅读(127) | 评论 (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 郭兴华 阅读(56) | 评论 (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("请输入有效的年分(YYYY):");
int year1=Integer.parseInt(input);//将字符串转化为整数
FormateDateOutput out=new FormateDateOutput();
out.setYear(year1);
if(year1!=0&&input.length()==4)
{
out.FormateDateStr();
}else{
System.out.println("输入的年份无效。");
}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("当前的时间是:"+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 郭兴华 阅读(85) | 评论 (0)编辑 收藏
CalendarTest.java

/*
*GregroianCalendar类的设置器与访问器
*/
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 郭兴华 阅读(238) | 评论 (0)编辑 收藏
仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页