Java課程設計第二版
⑴ 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課程設計題目答案
問題呢。。。。????