2014年7月12日 星期六

java程式設計題目---日期處理【印製月曆(整年度)】

請設計一個程式可以印製某一年整年的月曆,請使用者輸入年份及當年第一天(1月1日)是星期幾,其中0代表星期日,1至6分別代表星期一至星期六。範例如下:























  1. import java.util.Scanner;
  2. public class C1
  3. {
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner input = new Scanner(System.in);
  8. //提示使用者輸入年份和當年第一天資訊
  9. System.out.println("使用者輸入:");
  10. int year = input.nextInt();
  11. int a = input.nextInt();
  12. int i;
  13. int count = a + 1;
  14. int space = a;
  15. //印製1月份月曆
  16. //印出月曆抬頭
  17. System.out.println(year+"年1月份");
  18. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  19. " " + "Thu" + " " + "Fri" + " " +"Sat");
  20. //印製1月份月曆
  21. //設定該年一月月曆是從星期幾開始
  22. if( a == 1 )
  23. {
  24. System.out.print(" ");
  25. }
  26. if( a == 2)
  27. {
  28. System.out.print(" " + " " );
  29. }
  30. if( a == 3)
  31. {
  32. System.out.print(" " + " " + " " );
  33. }
  34. if( a == 4)
  35. {
  36. System.out.print(" " + " " + " " + " ");
  37. }
  38. if( a == 5)
  39. {
  40. System.out.print(" " + " " + " " + " " + " ");
  41. }
  42. if( a == 6)
  43. {
  44. System.out.print(" " + " " + " " + " " + " " + " ");
  45. }
  46. //印製1月份月曆
  47. //輸出結果
  48. for( i=1 ; i <= 31 ; i++ )
  49. {
  50. if(count % 7 == 1 )
  51. {
  52. System.out.printf("\n%3d",i); //在這裡會換行
  53. }
  54. else if(count % 7 == 0)
  55. {
  56. System.out.printf("%5d",i);
  57. }
  58. else if(count % 7 == 2)
  59. {
  60. System.out.printf("%5d",i);
  61. }
  62. else if(count % 7 == 3)
  63. {
  64. System.out.printf("%5d",i);
  65. }
  66. else if(count % 7 == 4)
  67. {
  68. System.out.printf("%5d",i);
  69. }
  70. else if(count % 7 == 5)
  71. {
  72. System.out.printf("%5d",i);
  73. }
  74. else if(count % 7 == 6)
  75. {
  76. System.out.printf("%5d",i);
  77. }
  78. space = count % 7;
  79. count = count + 1 ;
  80. }
  81. count = space + 1;
  82. System.out.println();//為了換行
  83. //印製2月份月曆
  84. //印出月曆抬頭
  85. System.out.println(year+"年2月份");
  86. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  87. " " + "Thu" + " " + "Fri" + " " +"Sat");
  88. //印製2月份月曆
  89. //設定該年二月月曆是從星期幾開始
  90. if( space == 1 )
  91. {
  92. System.out.print(" ");
  93. }
  94. if( space == 2)
  95. {
  96. System.out.print(" " + " " );
  97. }
  98. if( space == 3)
  99. {
  100. System.out.print(" " + " " + " " );
  101. }
  102. if( space == 4)
  103. {
  104. System.out.print(" " + " " + " " + " ");
  105. }
  106. if( space == 5)
  107. {
  108. System.out.print(" " + " " + " " + " " + " ");
  109. }
  110. if( space == 6)
  111. {
  112. System.out.print(" " + " " + " " + " " + " " + " ");
  113. }
  114. //印製2月份月曆
  115. //判斷是否為閏年,為閏年的結果
  116. if(year % 400 == 0 || year % 4 == 0 || year % 100 != 0 )
  117. {
  118. //輸出結果
  119. for( i=1 ; i <= 29 ; i++ )
  120. {
  121. if(count % 7 == 1 )
  122. {
  123. System.out.printf("\n%3d",i); //在這裡會換行
  124. }
  125. else if(count % 7 == 0)
  126. {
  127. System.out.printf("%5d",i);
  128. }
  129. else if(count % 7 == 2)
  130. {
  131. System.out.printf("%5d",i);
  132. }
  133. else if(count % 7 == 3)
  134. {
  135. System.out.printf("%5d",i);
  136. }
  137. else if(count % 7 == 4)
  138. {
  139. System.out.printf("%5d",i);
  140. }
  141. else if(count % 7 == 5)
  142. {
  143. System.out.printf("%5d",i);
  144. }
  145. else if(count % 7 == 6)
  146. {
  147. System.out.printf("%5d",i);
  148. }
  149. space = count % 7;
  150. count = count + 1 ;
  151. }
  152. }
  153. //印製2月份月曆
  154. //判斷是否為閏年,不為閏年的結果
  155. else
  156. {
  157. //輸出結果
  158. for( i=1 ; i <= 28 ; i++ )
  159. {
  160. if(count % 7 == 1 )
  161. {
  162. System.out.printf("\n%3d",i); //在這裡會換行
  163. }
  164. else if(count % 7 == 0)
  165. {
  166. System.out.printf("%5d",i);
  167. }
  168. else if(count % 7 == 2)
  169. {
  170. System.out.printf("%5d",i);
  171. }
  172. else if(count % 7 == 3)
  173. {
  174. System.out.printf("%5d",i);
  175. }
  176. else if(count % 7 == 4)
  177. {
  178. System.out.printf("%5d",i);
  179. }
  180. else if(count % 7 == 5)
  181. {
  182. System.out.printf("%5d",i);
  183. }
  184. else if(count % 7 == 6)
  185. {
  186. System.out.printf("%5d",i);
  187. }
  188. space = count % 7;
  189. count = count + 1 ;
  190. }
  191. }
  192. count = space + 1;
  193. System.out.println();//為了換行
  194. //印製3月份月曆
  195. //印出月曆抬頭
  196. System.out.println(year+"年3月份");
  197. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  198. " " + "Thu" + " " + "Fri" + " " +"Sat");
  199. //印製3月份月曆
  200. //設定該年三月月曆是從星期幾開始
  201. if( space == 1 )
  202. {
  203. System.out.print(" ");
  204. }
  205. if( space == 2)
  206. {
  207. System.out.print(" " + " " );
  208. }
  209. if( space == 3)
  210. {
  211. System.out.print(" " + " " + " " );
  212. }
  213. if( space == 4)
  214. {
  215. System.out.print(" " + " " + " " + " ");
  216. }
  217. if( space == 5)
  218. {
  219. System.out.print(" " + " " + " " + " " + " ");
  220. }
  221. if( space == 6)
  222. {
  223. System.out.print(" " + " " + " " + " " + " " + " ");
  224. }
  225. //印製3月份月曆
  226. //輸出結果
  227. for( i=1 ; i <= 31 ; i++ )
  228. {
  229. if(count % 7 == 1 )
  230. {
  231. System.out.printf("\n%3d",i); //在這裡會換行
  232. }
  233. else if(count % 7 == 0)
  234. {
  235. System.out.printf("%5d",i);
  236. }
  237. else if(count % 7 == 2)
  238. {
  239. System.out.printf("%5d",i);
  240. }
  241. else if(count % 7 == 3)
  242. {
  243. System.out.printf("%5d",i);
  244. }
  245. else if(count % 7 == 4)
  246. {
  247. System.out.printf("%5d",i);
  248. }
  249. else if(count % 7 == 5)
  250. {
  251. System.out.printf("%5d",i);
  252. }
  253. else if(count % 7 == 6)
  254. {
  255. System.out.printf("%5d",i);
  256. }
  257. space = count % 7;
  258. count = count + 1 ;
  259. }
  260. count = space + 1;
  261. System.out.println();//為了換行
  262. //印4月份月曆
  263. //印出月曆抬頭
  264. System.out.println(year+"年4月份");
  265. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" + " " + "Thu" + " " + "Fri" + " " +"Sat");
  266. //印製4月份月曆
  267. //設定該年四月月曆是從星期幾開始
  268. if( space == 1 )
  269. {
  270. System.out.print(" ");
  271. }
  272. if( space == 2)
  273. {
  274. System.out.print(" " + " " );
  275. }
  276. if( space == 3)
  277. {
  278. System.out.print(" " + " " + " " );
  279. }
  280. if( space == 4)
  281. {
  282. System.out.print(" " + " " + " " + " ");
  283. }
  284. if( space == 5)
  285. {
  286. System.out.print(" " + " " + " " + " " + " ");
  287. }
  288. if( space == 6)
  289. {
  290. System.out.print(" " + " " + " " + " " + " " + " ");
  291. }
  292. //印製4月份月曆
  293. //輸出結果
  294. for( i=1 ; i <= 30 ; i++ )
  295. {
  296. if(count % 7 == 1 )
  297. {
  298. System.out.printf("\n%3d",i); //在這裡會換行
  299. }
  300. else if(count % 7 == 0)
  301. {
  302. System.out.printf("%5d",i);
  303. }
  304. else if(count % 7 == 2)
  305. {
  306. System.out.printf("%5d",i);
  307. }
  308. else if(count % 7 == 3)
  309. {
  310. System.out.printf("%5d",i);
  311. }
  312. else if(count % 7 == 4)
  313. {
  314. System.out.printf("%5d",i);
  315. }
  316. else if(count % 7 == 5)
  317. {
  318. System.out.printf("%5d",i);
  319. }
  320. else if(count % 7 == 6)
  321. {
  322. System.out.printf("%5d",i);
  323. }
  324. space = count % 7;
  325. count = count + 1 ;
  326. }
  327. count = space + 1;
  328. System.out.println();//為了換行
  329. //印製5月份月曆
  330. //印出月曆抬頭
  331. System.out.println(year+"年5月份");
  332. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  333. " " + "Thu" + " " + "Fri" + " " +"Sat");
  334. //印製5月份月曆
  335. //設定該年五月月曆是從星期幾開始
  336. if( space == 1 )
  337. {
  338. System.out.print(" ");
  339. }
  340. if( space == 2)
  341. {
  342. System.out.print(" " + " " );
  343. }
  344. if( space == 3)
  345. {
  346. System.out.print(" " + " " + " " );
  347. }
  348. if( space == 4)
  349. {
  350. System.out.print(" " + " " + " " + " ");
  351. }
  352. if( space == 5)
  353. {
  354. System.out.print(" " + " " + " " + " " + " ");
  355. }
  356. if( space == 6)
  357. {
  358. System.out.print(" " + " " + " " + " " + " " + " ");
  359. }
  360.  
  361. //印製5月份月曆
  362. //輸出結果
  363. for( i=1 ; i <= 31 ; i++ )
  364. {
  365. if(count % 7 == 1 )
  366. {
  367. System.out.printf("\n%3d",i); //在這裡會換行
  368. }
  369. else if(count % 7 == 0)
  370. {
  371. System.out.printf("%5d",i);
  372. }
  373. else if(count % 7 == 2)
  374. {
  375. System.out.printf("%5d",i);
  376. }
  377. else if(count % 7 == 3)
  378. {
  379. System.out.printf("%5d",i);
  380. }
  381. else if(count % 7 == 4)
  382. {
  383. System.out.printf("%5d",i);
  384. }
  385. else if(count % 7 == 5)
  386. {
  387. System.out.printf("%5d",i);
  388. }
  389. else if(count % 7 == 6)
  390. {
  391. System.out.printf("%5d",i);
  392. }
  393. space = count % 7;
  394. count = count + 1 ;
  395. }
  396. count = space + 1;
  397. System.out.println();//為了換行
  398. //印製6月份月曆
  399. //印出月曆抬頭
  400. System.out.println(year+"年6月份");
  401. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  402. " " + "Thu" + " " + "Fri" + " " +"Sat");
  403. //印製6月份月曆
  404. //設定該年六月月曆是從星期幾開始
  405. if( space == 1 )
  406. {
  407. System.out.print(" ");
  408. }
  409. if( space == 2)
  410. {
  411. System.out.print(" " + " " );
  412. }
  413. if( space == 3)
  414. {
  415. System.out.print(" " + " " + " " );
  416. }
  417. if( space == 4)
  418. {
  419. System.out.print(" " + " " + " " + " ");
  420. }
  421. if( space == 5)
  422. {
  423. System.out.print(" " + " " + " " + " " + " ");
  424. }
  425. if( space == 6)
  426. {
  427. System.out.print(" " + " " + " " + " " + " " + " ");
  428. }
  429. //印製6月份月曆
  430. //輸出結果
  431. for( i=1 ; i <= 30 ; i++ )
  432. {
  433. if(count % 7 == 1 )
  434. {
  435. System.out.printf("\n%3d",i); //在這裡會換行
  436. }
  437. else if(count % 7 == 0)
  438. {
  439. System.out.printf("%5d",i);
  440. }
  441. else if(count % 7 == 2)
  442. {
  443. System.out.printf("%5d",i);
  444. }
  445. else if(count % 7 == 3)
  446. {
  447. System.out.printf("%5d",i);
  448. }
  449. else if(count % 7 == 4)
  450. {
  451. System.out.printf("%5d",i);
  452. }
  453. else if(count % 7 == 5)
  454. {
  455. System.out.printf("%5d",i);
  456. }
  457. else if(count % 7 == 6)
  458. {
  459. System.out.printf("%5d",i);
  460. }
  461. space = count % 7;
  462. count = count + 1 ;
  463. }
  464. count = space + 1;
  465. System.out.println();//為了換行
  466. //印製7月份月曆
  467. //印出月曆抬頭
  468. System.out.println(year+"年7月份");
  469. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  470. " " + "Thu" + " " + "Fri" + " " +"Sat");
  471. //印製7月份月曆
  472. //設定該年七月月曆是從星期幾開始
  473. if( space == 1 )
  474. {
  475. System.out.print(" ");
  476. }
  477. if( space == 2)
  478. {
  479. System.out.print(" " + " " );
  480. }
  481. if( space == 3)
  482. {
  483. System.out.print(" " + " " + " " );
  484. }
  485. if( space == 4)
  486. {
  487. System.out.print(" " + " " + " " + " ");
  488. }
  489. if( space == 5)
  490. {
  491. System.out.print(" " + " " + " " + " " + " ");
  492. }
  493. if( space == 6)
  494. {
  495. System.out.print(" " + " " + " " + " " + " " + " ");
  496. }
  497.  
  498. //印製7月份月曆
  499. //輸出結果
  500. for( i=1 ; i <= 31 ; i++ )
  501. {
  502. if(count % 7 == 1 )
  503. {
  504. System.out.printf("\n%3d",i); //在這裡會換行
  505. }
  506. else if(count % 7 == 0)
  507. {
  508. System.out.printf("%5d",i);
  509. }
  510. else if(count % 7 == 2)
  511. {
  512. System.out.printf("%5d",i);
  513. }
  514. else if(count % 7 == 3)
  515. {
  516. System.out.printf("%5d",i);
  517. }
  518. else if(count % 7 == 4)
  519. {
  520. System.out.printf("%5d",i);
  521. }
  522. else if(count % 7 == 5)
  523. {
  524. System.out.printf("%5d",i);
  525. }
  526. else if(count % 7 == 6)
  527. {
  528. System.out.printf("%5d",i);
  529. }
  530. space = count % 7;
  531. count = count + 1 ;
  532. }
  533. count = space + 1;
  534. System.out.println(); //為了換行
  535. //印製8月份月曆
  536. //印出月曆抬頭
  537. System.out.println(year+"年8月份");
  538. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  539. " " + "Thu" + " " + "Fri" + " " +"Sat");
  540. //印製8月份月曆
  541. //設定該年八月月曆是從星期幾開始
  542. if( space == 1 )
  543. {
  544. System.out.print(" ");
  545. }
  546. if( space == 2)
  547. {
  548. System.out.print(" " + " " );
  549. }
  550. if( space == 3)
  551. {
  552. System.out.print(" " + " " + " " );
  553. }
  554. if( space == 4)
  555. {
  556. System.out.print(" " + " " + " " + " ");
  557. }
  558. if( space == 5)
  559. {
  560. System.out.print(" " + " " + " " + " " + " ");
  561. }
  562. if( space == 6)
  563. {
  564. System.out.print(" " + " " + " " + " " + " " + " ");
  565. }
  566.  
  567. //印製8月份月曆
  568. //輸出結果
  569. for( i=1 ; i <= 31 ; i++ )
  570. {
  571. if(count % 7 == 1 )
  572. {
  573. System.out.printf("\n%3d",i); //在這裡會換行
  574. }
  575. else if(count % 7 == 0)
  576. {
  577. System.out.printf("%5d",i);
  578. }
  579. else if(count % 7 == 2)
  580. {
  581. System.out.printf("%5d",i);
  582. }
  583. else if(count % 7 == 3)
  584. {
  585. System.out.printf("%5d",i);
  586. }
  587. else if(count % 7 == 4)
  588. {
  589. System.out.printf("%5d",i);
  590. }
  591. else if(count % 7 == 5)
  592. {
  593. System.out.printf("%5d",i);
  594. }
  595. else if(count % 7 == 6)
  596. {
  597. System.out.printf("%5d",i);
  598. }
  599. space = count % 7;
  600. count = count + 1
  601. }
  602. count = space + 1;
  603. System.out.println();//為了換行
  604. //印製9月份月曆
  605. //印出月曆抬頭
  606. System.out.println(year+"年9月份");
  607. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  608. " " + "Thu" + " " + "Fri" + " " +"Sat");
  609. //印製9月份月曆
  610. //設定該年九月月曆是從星期幾開始
  611. if( space == 1 )
  612. {
  613. System.out.print(" ");
  614. }
  615. if( space == 2)
  616. {
  617. System.out.print(" " + " " );
  618. }
  619. if( space == 3)
  620. {
  621. System.out.print(" " + " " + " " );
  622. }
  623. if( space == 4)
  624. {
  625. System.out.print(" " + " " + " " + " ");
  626. }
  627. if( space == 5)
  628. {
  629. System.out.print(" " + " " + " " + " " + " ");
  630. }
  631. if( space == 6)
  632. {
  633. System.out.print(" " + " " + " " + " " + " " + " ");
  634. }
  635.  
  636. //印製9月份月曆
  637. //輸出結果
  638. for( i=1 ; i <= 30 ; i++ )
  639. {
  640. if(count % 7 == 1 )
  641. {
  642. System.out.printf("\n%3d",i);
  643. }
  644. else if(count % 7 == 0)
  645. {
  646. System.out.printf("%5d",i);
  647. }
  648. else if(count % 7 == 2)
  649. {
  650. System.out.printf("%5d",i);
  651. }
  652. else if(count % 7 == 3)
  653. {
  654. System.out.printf("%5d",i);
  655. }
  656. else if(count % 7 == 4)
  657. {
  658. System.out.printf("%5d",i);
  659. }
  660. else if(count % 7 == 5)
  661. {
  662. System.out.printf("%5d",i);
  663. }
  664. else if(count % 7 == 6)
  665. {
  666. System.out.printf("%5d",i);
  667. }
  668. space = count % 7;
  669. count = count + 1 ;
  670. }
  671. count = space + 1;
  672. System.out.println();//為了換行
  673. //印製10月份月曆
  674. //印出月曆抬頭
  675. System.out.println(year+"年10月份");
  676. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  677. " " + "Thu" + " " + "Fri" + " " +"Sat");
  678. //印製10月份月曆
  679. //設定該年十月月曆是從星期幾開始 if( space == 1 )
  680. {
  681. System.out.print(" ");
  682. }
  683. if( space == 2)
  684. {
  685. System.out.print(" " + " " );
  686. }
  687. if( space == 3)
  688. {
  689. System.out.print(" " + " " + " " );
  690. }
  691. if( space == 4)
  692. {
  693. System.out.print(" " + " " + " " + " ");
  694. }
  695. if( space == 5)
  696. {
  697. System.out.print(" " + " " + " " + " " + " ");
  698. }
  699. if( space == 6)
  700. {
  701. System.out.print(" " + " " + " " + " " + " " + " ");
  702. }
  703. //印製10月份月曆
  704. //輸出結果
  705. for( i=1 ; i <= 31 ; i++ )
  706. {
  707. if(count % 7 == 1 )
  708. {
  709. System.out.printf("\n%3d",i); //在這裡會換行
  710. }
  711. else if(count % 7 == 0)
  712. {
  713. System.out.printf("%5d",i);
  714. }
  715. else if(count % 7 == 2)
  716. {
  717. System.out.printf("%5d",i);
  718. }
  719. else if(count % 7 == 3)
  720. {
  721. System.out.printf("%5d",i);
  722. }
  723. else if(count % 7 == 4)
  724. {
  725. System.out.printf("%5d",i);
  726. }
  727. else if(count % 7 == 5)
  728. {
  729. System.out.printf("%5d",i);
  730. }
  731. else if(count % 7 == 6)
  732. {
  733. System.out.printf("%5d",i);
  734. }
  735. space = count % 7;
  736. count = count + 1 ;
  737. }
  738. count = space + 1;
  739. System.out.println(); //為了換行
  740.  
  741. //印製11月份月曆
  742. //印出月曆抬頭
  743. System.out.println(year+"年11月份");
  744. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  745. " " + "Thu" + " " + "Fri" + " " +"Sat");
  746. //印製11月份月曆
  747. //設定該年十一月月曆是從星期幾開始
  748. if( space == 1 )
  749. {
  750. System.out.print(" ");
  751. }
  752. if( space == 2)
  753. {
  754. System.out.print(" " + " " );
  755. }
  756. if( space == 3)
  757. {
  758. System.out.print(" " + " " + " " );
  759. }
  760. if( space == 4)
  761. {
  762. System.out.print(" " + " " + " " + " ");
  763. }
  764. if( space == 5)
  765. {
  766. System.out.print(" " + " " + " " + " " + " ");
  767. }
  768. if( space == 6)
  769. {
  770. System.out.print(" " + " " + " " + " " + " " + " ");
  771. }
  772.  
  773. //印製11月份月曆
  774. //輸出結果
  775. for( i=1 ; i <= 30 ; i++ )
  776. {
  777. if(count % 7 == 1 )
  778. {
  779. System.out.printf("\n%3d",i); //在這裡會換行
  780. }
  781. else if(count % 7 == 0)
  782. {
  783. System.out.printf("%5d",i);
  784. }
  785. else if(count % 7 == 2)
  786. {
  787. System.out.printf("%5d",i);
  788. }
  789. else if(count % 7 == 3)
  790. {
  791. System.out.printf("%5d",i);
  792. }
  793. else if(count % 7 == 4)
  794. {
  795. System.out.printf("%5d",i);
  796. }
  797. else if(count % 7 == 5)
  798. {
  799. System.out.printf("%5d",i);
  800. }
  801. else if(count % 7 == 6)
  802. {
  803. System.out.printf("%5d",i);
  804. }
  805. space = count % 7;
  806. count = count + 1 ;
  807. }
  808.  
  809. count = space + 1;
  810. System.out.println(); //為了換行
  811.  
  812. //印製12月份月曆
  813. //印出月曆抬頭
  814. System.out.println(year+"年12月份");
  815. System.out.println("Sun" + " " + "Mon" + " " + "Tue" + " " + "Wed" +
  816. " " + "Thu" + " " + "Fri" + " " +"Sat");
  817. //印製12月份月曆
  818. //設定該年十二月月曆是從星期幾開始
  819. if( space == 1 )
  820. {
  821. System.out.print(" ");
  822. }
  823. if( space == 2)
  824. {
  825. System.out.print(" " + " " );
  826. }
  827. if( space == 3)
  828. {
  829. System.out.print(" " + " " + " " );
  830. }
  831. if( space == 4)
  832. {
  833. System.out.print(" " + " " + " " + " ");
  834. }
  835. if( space == 5)
  836. {
  837. System.out.print(" " + " " + " " + " " + " ");
  838. }
  839. if( space == 6)
  840. {
  841. System.out.print(" " + " " + " " + " " + " " + " ");
  842. }
  843.  
  844. //印製12月份月曆
  845. //輸出結果
  846. for( i=1 ; i <= 31 ; i++ )
  847. {
  848. if(count % 7 == 1 )
  849. {
  850. System.out.printf("\n%3d",i); //在這裡會換行
  851. }
  852. else if(count % 7 == 0)
  853. {
  854. System.out.printf("%5d",i);
  855. }
  856. else if(count % 7 == 2)
  857. {
  858. System.out.printf("%5d",i);
  859. }
  860. else if(count % 7 == 3)
  861. {
  862. System.out.printf("%5d",i);
  863. }
  864. else if(count % 7 == 4)
  865. {
  866. System.out.printf("%5d",i);
  867. }
  868. else if(count % 7 == 5)
  869. {
  870. System.out.printf("%5d",i);
  871. }
  872. else if(count % 7 == 6)
  873. {
  874. System.out.printf("%5d",i);
  875. }
  876. space = count % 7;
  877. count = count + 1 ;
  878. }
  879. }
  880. }

沒有留言:

張貼留言

Go(Golang)程式語言 設定GCC

下載MSYS2:  https://www.msys2.org/ 安裝 程式開始執行後輸入: pacman -Syu y y 在安裝目錄底下找到msys2.exe,雙擊執行 輸入指令: pacman -Su pacman -S --needed base-devel mingw-...