標題:
TQC102顯示系統時間 ~~ 請各位把程式貼上來~~
[打印本頁]
作者:
ray
時間:
2011-12-10 20:51
標題:
TQC102顯示系統時間 ~~ 請各位把程式貼上來~~
用回復貼在這邊!
作者:
chuangjoy
時間:
2011-12-10 21:14
TQC102
import java.lang.*;
import java.util.*;
public class TQC102
{
public static void main(String[] args)
{
System.out.println("------------------\n 當地時間 \n------------------");
Calendar now = Calendar.getInstance();
String[] week = {"","星期一","星期二","星期三","星期四","星期五","星期六","星期天"};
String[] APM = {"上午","下午"};
System.out.println(now.get(Calendar.YEAR)+"/"+now.get(Calendar.MONTH)+"/"+now.get(Calendar.DATE)+" "+APM[now.get(Calendar.AM_PM)]+" "+now.get(Calendar.HOUR)+":"+now.get(Calendar.MINUTE));
System.out.println(now.get(Calendar.YEAR)+"/"+now.get(Calendar.MONTH)+"/"+now.get(Calendar.DATE)+" "+APM[now.get(Calendar.AM_PM)]+" "+now.get(Calendar.HOUR)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND));
System.out.println(now.get(Calendar.YEAR)+"年"+now.get(Calendar.MONTH)+"月"+now.get(Calendar.DATE)+"日 "+APM[now.get(Calendar.AM_PM)]+now.get(Calendar.HOUR)+"時"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒");
System.out.println(now.get(Calendar.YEAR)+"年"+now.get(Calendar.MONTH)+"月"+now.get(Calendar.DATE)+"日 "+week[now.get(Calendar.DAY_OF_WEEK)]+" "+APM[now.get(Calendar.AM_PM)]+now.get(Calendar.HOUR)+"時"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒 CST");
}
}
複製代碼
TQC103
import java.lang.*;
import java.util.*;
public class TQC103
{
public static void main(String[] args)
{
int num, i;
Scanner in = new Scanner(System.in); //輸入
Random rnd = new Random((new Date()).getTime()); //亂數
while(true){
System.out.print("請輸入欲產生之亂數個數:");
num = in.nextInt();
int[] sort = new int[num];
for(i=0; i<num; i++)
sort[i] = rnd.nextInt(1000); //產生亂數
for(i=0; i<num; i++){
for(int j=i+1;j<num;j++) //排序
{
if(sort[i] > sort[j]){
int tmp = sort[i];
sort[i] = sort[j];
sort[j] = tmp;
}
}
}
for(i=0; i<num; i++)
System.out.println(sort[i]);
}
}
}
複製代碼
作者:
p17johnny
時間:
2011-12-11 15:15
有個問題想要問一下老師,不知 在後面的 "CST" 要如何顯示出來??
import java.util.*;
import java.text.*;
public class TQC102_2 {
public static void main(String[] args) {
Date time = Calendar.getInstance().getTime();
SimpleDateFormat j1 =
new SimpleDateFormat("yyyy/M/d a hh:mm");
SimpleDateFormat j2 =
new SimpleDateFormat("yyyy/M/d a hh:mm:ss");
SimpleDateFormat j3 =
new SimpleDateFormat("yyyy年M月d日 a hh時mm分ss秒");
SimpleDateFormat j4 =
new SimpleDateFormat("yyyy年M月d日 E a hh時mm分ss秒 ");
System.out.println("-------------------");
System.out.println("======= Now Time======");
System.out.println("-------------------");
System.out.println(j1.format(time));
System.out.println(j2.format(time));
System.out.println(j3.format(time));
System.out.println(j4.format(time));
}
}
複製代碼
作者:
p17johnny
時間:
2011-12-11 15:22
輸出的字跟紙上的"執行結果參考畫面" 不一樣 他得很整齊 可是我的變成這樣ㄌ...
1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27
4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54
複製代碼
//我沒宣告 因為用不到
//請大家幫幫忙!!!修一下程式
public class TQC108 {
public static void main(String[] args) {
int a[][]=new int [9][9];
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
a[i][j]=(i+1)*(j+1);
}
for(int i=0;i<9;i++){
for(int j=0;j<9;j++)
System.out.print((i+1)+"*"+(j+1)+"="+a[i][j]+" "); //我的排版怪怪的?不知大家能夠幫幫忙?
System.out.println();
}
}
}
複製代碼
作者:
ray
時間:
2011-12-12 00:22
CST 請先使用"CST"這個字串直接秀出來
下次上課我會講這個題目真正要使用的作法,它算是程式開發國際化的一個主題!
作者:
b1081081
時間:
2011-12-16 22:32
import java.lang.*;
import java.util.*;
public class calendar{
public static void main(String[] args){
System.out.println("----------------------");
System.out.println(" 當地時間 ");
System.out.println("----------------------");
String apm[] = {"上午","下午"};
String week[] = {"","星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
Calendar now = Calendar.getInstance();
System.out.println(now.get(Calendar.YEAR)+"/"+now.get(Calendar.MONTH)+"/"+now.get(Calendar.DATE)+" "+apm[now.get(Calendar.AM_PM)]+" "+now.get(Calendar.HOUR)+":"+now.get(Calendar.MINUTE));
System.out.println(now.get(Calendar.YEAR)+"/"+now.get(Calendar.MONTH)+"/"+now.get(Calendar.DATE)+" "+apm[now.get(Calendar.AM_PM)]+" "+now.get(Calendar.HOUR)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND));
System.out.println(now.get(Calendar.YEAR)+"年"+now.get(Calendar.MONTH)+"月"+now.get(Calendar.DATE)+"日 "+apm[now.get(Calendar.AM_PM)]+now.get(Calendar.HOUR)+"時"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒");
System.out.println(now.get(Calendar.YEAR)+"年"+now.get(Calendar.MONTH)+"月"+now.get(Calendar.DATE)+"日 "+week[now.get(Calendar.DAY_OF_WEEK)]+apm[now.get(Calendar.AM_PM)]+now.get(Calendar.HOUR)+"時"+now.get(Calendar.MINUTE)+"分"+now.get(Calendar.SECOND)+"秒");
}
}
作者:
p17johnny
時間:
2011-12-17 19:54
import java.util.*;
import java.text.*;
public class TQC102_3
{
public static void main(String args[])
{
Locale locale = new Locale("tw", "TW");
System.out.println(" ");
System.out.println("------------------------");
System.out.println(" 當地時間");
System.out.println("------------------------");
Date date = new Date();
DateFormat dateformat = DateFormat.getDateTimeInstance(3, 3, locale);
System.out.println(dateformat.format(date));
dateformat = DateFormat.getDateTimeInstance(2, 2, locale);
System.out.println(dateformat.format(date));
dateformat = DateFormat.getDateTimeInstance(1, 1, locale);
System.out.println(dateformat.format(date));
dateformat = DateFormat.getDateTimeInstance(0, 0, locale);
System.out.println(dateformat.format(date));
}
}
複製代碼
作者:
p17johnny
時間:
2011-12-17 19:57
煩了煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....煩煩煩煩煩.....
作者:
a3218290
時間:
2011-12-17 20:06
import java.lang.*;
import java.util.*;
public class TQC102
{
public static void main(String[] args)
{
System.out.println("---------------------------");
System.out.println(" 當地時間 ");
System.out.println("---------------------------");
String apm ;
Calendar now = Calendar.getInstance();
int year,mon,date,hour,min,sec,weekk ;
year = now.get(Calendar.YEAR);
mon = now.get(Calendar.MONTH);
date = now.get(Calendar.DATE);
hour = now.get(Calendar.HOUR);
min = now.get(Calendar.MINUTE);
sec = now.get(Calendar.SECOND);
weekk = now.get(Calendar.DAY_OF_WEEK) ;
if(now.get(Calendar.AM_PM) == Calendar.PM )
apm = "下午" ;
else apm = "上午" ;
String[] week = new String[9] ;
week[2] = "星期一" ;
week[3] = "星期二" ;
week[4] = "星期三" ;
week[5] = "星期四" ;
week[6] = "星期五" ;
week[7] = "星期六" ;
week[1] = "星期日" ;
System.out.println(year + "/" + mon + "/" + date + " " +apm+ " " +hour +":" + min );
System.out.println(year + "/" + mon + "/" + date + " " +apm+ " " +String.format("%02d",hour) +":" + String.format("%02d",min)+ ":" +String.format("%02d",sec) );
System.out.println(year + "年" + mon + "月" + date + "日 " +apm+ " " +String.format("%02d",hour) +"時" + String.format("%02d",min)+ "分" +String.format("%02d",sec)+ "秒" );
System.out.println(year + "年" + mon + "月" + date + "日 "+ week[weekk]+" "+apm+ " " +String.format("%02d",hour) +"時" + String.format("%02d",min)+ "分" +String.format("%02d",sec)+ "秒 CST" );
}
}
複製代碼
作者:
許逸瑋
時間:
2011-12-17 21:05
import java.lang.*;
import java.util.*;
import java.util.Scanner;
import java.text.*;
public class TQC102
{
public static void main(String[] argv) {
Date currentDate = new Date();
Locale loc = new Locale("zh", "TW");
DateFormat dateformat;
dateformat = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT,loc);
System.out.println(dateformat.format(currentDate));
dateformat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,loc);
System.out.println(dateformat.format(currentDate));
dateformat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG,loc);
System.out.println(dateformat.format(currentDate));
dateformat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,loc);
System.out.println(dateformat.format(currentDate));
//SHORT, MEDIUM, LONG, FULL
}
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2