關(guān)于星期的問題(標(biāo)題: 世紀(jì)末的星期)
曾有邪教稱1999年12月31日是世界末日狭吼。當(dāng)然該謠言已經(jīng)不攻自破。
還有人稱今后的某個(gè)世紀(jì)末的12月31日殖妇,如果是星期一則會...
有趣的是刁笙,任何一個(gè)世紀(jì)末的年份的12月31日都不可能是星期一!!
于是,“謠言制造商”又修改為星期日......
1999年的12月31日是星期五谦趣,請問:未來哪一個(gè)離我們最近的一個(gè)世紀(jì)末年(即xx99年)的12月31日正好是星期天(即星期日)?
代碼:
public class ShiJiMo {
public static void main(String[] args) {
int t = 1;
for(int year=1999;t != 0;year += 100){
int day=(year-1)+(year-1)/4-(year-1)/100+(year-1)/400+365;
if((t=day%7)==0)
System.out.println(year+"年12月31日是星期日");
}
}
}
打印圖形
輸出六邊形疲吸,
- 當(dāng)邊長為3的時(shí)候:
* * *
* * * *
* * * * *
* * * *
* * *
- 當(dāng)邊長為4的時(shí)候:
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
代碼:
public class TuXing {
static void output(int n){
System.out.println("當(dāng)邊長為"+n+"的時(shí)候");
for(int i=-n+1; i<n; i++){
for(int j=Math.abs(i);j>0;j--)
System.out.print(" ");
for(int j=0;j<2*n-Math.abs(i)-1;j++)
System.out.print("* ");
System.out.println();
}
}
public static void main(String[] args) {
output(3);
output(4);
}
}