当前位置:首页 » 课程设计 » Java课程设计第二版

Java课程设计第二版

发布时间: 2021-01-27 17:40:14

⑴ java课程设计(第二版,清华大学出版社)里面的保存计算过程的计算器怎么把当前时间也保存到该文件

我没有那本书 也不知道这个程序的代码
我帮你找了一下java中获取当前时间的资料
然后你修改一下就可以了吧 应该很简单的

有两种方法:

方法一:用java.util.Date类来实现,并结合java.text.DateFormat类来实现时间的格式化,看下面代码:

import java.util.*;

import java.text.*;

//以下默认时间日期显示方式都是汉语语言方式

//一般语言就默认汉语就可以了,时间日期的格式默认为MEDIUM风格,比如:2008-6-16 20:54:53

//以下显示的日期时间都是再Date类的基础上的来的,还可以利用Calendar类来实现见类TestDate2.java

public class TestDate {

public static void main(String[] args) {

Date now = new Date();

Calendar cal = Calendar.getInstance();

DateFormat d1 = DateFormat.getDateInstance(); //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53)

String str1 = d1.format(now);

DateFormat d2 = DateFormat.getDateTimeInstance();

String str2 = d2.format(now);

DateFormat d3 = DateFormat.getTimeInstance();

String str3 = d3.format(now);

DateFormat d4 = DateFormat.getInstance(); //使用SHORT风格显示日期和时间

String str4 = d4.format(now);

DateFormat d5 = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL); //显示日期,周,时间(精确到秒)

String str5 = d5.format(now);

DateFormat d6 = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); //显示日期。时间(精确到秒)

String str6 = d6.format(now);

DateFormat d7 = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT); //显示日期,时间(精确到分)

String str7 = d7.format(now);

DateFormat d8 = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); //显示日期,时间(精确到分)

String str8 = d8.format(now);//与SHORT风格相比,这种方式最好用

System.out.println("用Date方式显示时间: " + now);//此方法显示的结果和Calendar.getInstance().getTime()一样

System.out.println("用DateFormat.getDateInstance()格式化时间后为:" + str1);

System.out.println("用DateFormat.getDateTimeInstance()格式化时间后为:" + str2);

System.out.println("用DateFormat.getTimeInstance()格式化时间后为:" + str3);

System.out.println("用DateFormat.getInstance()格式化时间后为:" + str4);

System.out.println("用DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL)格式化时间后为:" + str5);

System.out.println("用DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG)格式化时间后为:" + str6);

System.out.println("用DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT)格式化时间后为:" + str7);

System.out.println("用DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM)格式化时间后为:" + str8);

}

}

运行结果:

用Date方式显示时间: Mon Jun 16 20:54:53 CST 2008

用DateFormat.getDateInstance()格式化时间后为:2008-6-16

用DateFormat.getDateTimeInstance()格式化时间后为:2008-6-16 20:54:53

用DateFormat.getTimeInstance()格式化时间后为:20:54:53

用DateFormat.getInstance()格式化时间后为:08-6-16 下午8:54

用DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL)格式化时间后为

:2008年6月16日 星期一 下午08时54分53秒 CST

用DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG)格式化时间后为

:2008年6月16日 下午08时54分53秒

用DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT)格式化时间后

为:08-6-16 下午8:54

用DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM)格式化时间

后为:2008-6-16 20:54:53

方法二:用java.util.Calendar类来实现,看下面:

import java.util.*;

import java.text.*;

//以下是利用Calendar类来实现日期时间的,和Date类相比较比较简单

public class TestDate2 {

public static void main(String[] args) {

Calendar ca = Calendar.getInstance();

int year = ca.get(Calendar.YEAR);//获取年份

int month=ca.get(Calendar.MONTH);//获取月份

int day=ca.get(Calendar.DATE);//获取日

int minute=ca.get(Calendar.MINUTE);//分

int hour=ca.get(Calendar.HOUR);//小时

int second=ca.get(Calendar.SECOND);//秒

int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK);

System.out.println("用Calendar.getInstance().getTime()方式显示时间: " + ca.getTime());

System.out.println("用Calendar获得日期是:" + year +"年"+ month +"月"+ day + "日");

System.out.println("用Calendar获得时间是:" + hour +"时"+ minute +"分"+ second +"秒");

System.out.println(WeekOfYear);//显示今天是一周的第几天(我做的这个例子正好是周二,故结果显示2,如果你再周6运行,那么显示6)

}

}

运行结果是:

用Calendar.getInstance().getTime()方式显示时间: Mon Jun 16 21:54:21 CST 2008

用Calendar获得日期是:2008年5月16日

用Calendar获得时间是:9时54分21秒

2

总结:中的来说,方法二是最方便的,方法一显得分笨拙,不过看个人喜欢了。

还有一种方法利用
System.currentTimeMillis()

也可以的,下次再总结这种方法。

⑵ JAVA课程设计(急用!谢谢!)

public class Array
{
public static int[] random(int n) //产生n个随机数,返回整型数组
{
if (n>0)
{
int table[] = new int[n];
for (int i=0; i<table.length; i++)
table[i] = (int)(Math.random()*50); //产生一个0~100之间的随机数
return table; //返回一个数组
}
return null;
}

public static void print(int[] table) //输出数组元素
{
if (table!=null)
for (int i=0; i<table.length; i++)
System.out.print(" "+table[i]);
System.out.println();
}

public static void sortNum(int[] table) //直接插入排序
{ //数组是引用类型,元素值将被改变
System.out.println("排序完成:");
for (int i=1; i<table.length; i++) //n-1趟扫描
{
int temp=table[i], j; //每趟将table[i]插入到前面已排序的序列中
// System.out.print("移动");
for (j=i-1; j>-1 && temp<table[j]; j--) //将前面较大元素向后移动
{
// System.out.print(table[j]+", ");
table[j+1] = table[j];
}
table[j+1] = temp; //temp值到达插入位置
}
}

public static void main(String[] args)
{
int[] table=new int[20];
table=Array.random(20);
Array.sortNum(table);
Array.print(table);
}
}

刚刚查到的,你试试吧。不知道那个高人编的。

⑶ 求java课程设计耿祥义版电子书

附件里面就是了。 自己电脑访问下载去吧。

⑷ 求java课程设计

我正在写一个网络版的中国象棋游戏,虽然还没有完成,不过游戏的功能已专经实现了,有UML图,和文档属说明,当然不全,因为还未完成,这个程序对于你来说是复杂了点,不过代码里我都有写注释。

我是用eclipse开发的,JDK1.6,我整个项目打包给你,如果你连这个怎么导入也不会,我也没办法了。

⑸ Java课程设计题目

这个控制台模拟的话很简单啊,使用switch语句,1-7对应选下,case之后再进行if语句判断就好了啊,程序模拟的话,自己做一个输入认证,当做登陆界面,后面的功能选项其实建模之后的模块而已,分别写7个pannel,对应控制选项= =。

⑹ JAVA课程设计,急求啊!跪求各位大神解救TAT

建数据库和数据表语句如下, 可以在sql 2000 2005 2008里面执行

createdatabaseshoolDB;
useshoolDB;
createtablestudent(
stuIDvarchar(20),
snamevarchar(20),
sclassvarchar(20),
sageint,
ssexvarchar(10)
)
insertintostudentvalues('1200101011','张红','软件1班',19,'男');
insertintostudentvalues('1200101013','王林','会计2班',20,'女');
insertintostudentvalues('1200101014','李红','计算1班',19,'男');
insertintostudentvalues('1200101017','王静天','软件1班',21,'男');

java工程里面需要导入sql的jar驱动包,

java代码如下:

importjava.io.FileNotFoundException;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.sql.SQLException;

/**
*java读取数据库内容并输出
*@authoryoung
*
*/
publicclassSQLToJavaTest{
publicstaticvoidmain(String[]args)throwsFileNotFoundException{
//定义数据库驱动
Stringdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//数据库连接URL
Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=shoolDB";
Connectionconn=null;
try{

//加载数据库驱动
Class.forName(driver);
//创建数据库连接
conn=DriverManager.getConnection(url,"sa","1234");
//创建预编译SQL对象
PreparedStatementps=conn
.prepareStatement("select*fromstudent");
//执行SQL,获取结果集rs
ResultSetrs=ps.executeQuery();
//处理结果集
System.out.println("学生信息为:");
while(rs.next()){
System.out.println("学号:"+rs.getString("stuID")
+".姓名:"+rs.getString("sname")
+".班级:"+rs.getString("sclass")
+".年龄:"+rs.getInt("sage")
+".性别:"+rs.getString("ssex"));
}
}catch(ClassNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
System.out.println("加载数据库失败");
System.exit(1);
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
System.out.println("数据库连接错误");
System.exit(1);
}finally{
if(conn!=null){
try{
//关闭数据库连接
conn.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}
}

⑺ JAVA课程设计题目答案

问题呢。。。。????

热点内容
幼师专业怎么样 发布:2021-03-16 21:42:13 浏览:24
音乐小毛驴故事 发布:2021-03-16 21:40:57 浏览:196
昂立中学生教育闸北 发布:2021-03-16 21:40:47 浏览:568
建筑业一建报考条件 发布:2021-03-16 21:39:53 浏览:666
2017年教师资格注册结果 发布:2021-03-16 21:39:49 浏览:642
中国教师资格证查分 发布:2021-03-16 21:39:41 浏览:133
踵什么成语有哪些 发布:2021-03-16 21:38:20 浏览:962
东营幼师专业学校 发布:2021-03-16 21:35:26 浏览:467
机械电子研究生课程 发布:2021-03-16 21:33:36 浏览:875
杭州朝日教育培训中心怎么样 发布:2021-03-16 21:33:28 浏览:238