第六届全国信息技术应用水平大赛Java组复赛B卷试题答案
1、?九九乘法口訣表是學習算數乘法的基礎,用一個for循環編程實現并顯示九九乘法口訣表,程序運行顯示結果如下所示。(25分)?
1*1=1?
1*2=2?2*2=4?
1*3=3?2*3=6?3*3=9?
1*4=4?2*4=8?3*4=12?4*4=16?
1*5=5?2*5=10?3*5=15?4*5=20?5*5=25?
1*6=6?2*6=12?3*6=18?4*6=24?5*6=30?6*6=36?
1*7=7?2*7=14?3*7=21?4*7=28?5*7=35?6*7=42?7*7=49?
1*8=8?2*8=16?3*8=24?4*8=32?5*8=40?6*8=48?7*8=56?8*8=64?
1*9=9?2*9=18?3*9=27?4*9=36?5*9=45?6*9=54?7*9=63?8*9=72?9*9=81
2、?編寫一個Java應用程序,定義一個表示學生的類Student,包括屬性:學號、班級、姓名、性別、年齡,以及方法:獲得學號、獲得班級號、獲得年齡、設置年齡。創建這個類的對象并驗證各個方法。(20分)
3、?字符串是一串包含一定序列的字符數據,Java的String類型的數據是具有不變性的,請編程實現某一個指定字符串的反序輸出。(25分)
要求如下:
(1)不能使用StringBuffer的reverse()方法;
(2)指定字符串為“第六屆全國信息技術應用水平大賽”。
4、?編寫一個Java應用程序,程序運行后,要求到指定的文件夾(比如d:\work目錄)查找后綴為java的文件,取出并保存到d:\test目錄下。(30分)
附加題:
5、?先設計一個類:Student,包含3個成員變量:學號、姓名、英語成績,并實現賦成員變量初值的構造方法。然后編寫程序,使用Hashtable()創建一個散列表,存放Student對象,每個Student對象用該對象的學號作為關鍵字,檢索學號為199902的元素并顯示,然后遍歷當前散列表并顯示所有元素,結果如下圖所示。(20分)
6、?編程實現輸入格式為“yyyy-mm-dd”的字符串,獲得一個給定的日期,計算此日期的下一天的日期并輸出,程序驗證時候,要考慮任意日期是月底、年底、閏年的情況。(30分)
T1:package Six;
public class B1 {
?public static void main(String[] args) {
??
??for (int i = 1, j = 1; i <= 9; j++) {
???System.out.print(j + "x" + i + "=" + j * i + "\t");
???if (j == i) {
????i++;
????j = 0;
????System.out.println();
???}
??}
?}
}
?
?
T2:
package ITAT;
public class SixthB2 {
?
?public static void main(String[] args) {
??
??Student3 student = new Student3(1001,2,"林郭隆",22);
??System.out.println("獲得學號: "+student.getNumber());
??System.out.println("獲得班級號: "+student.getBanJi());
??System.out.println("獲得年齡: "+student.getAge());
??student.setAge(18);
??System.out.println("設置后的年齡: "+student.getAge());
?}
}
class Student3{
?private int number;
?private int banJi;
?private String name;
?private int age;
?
?public Student3(int number, int banJi, String name, int age) {
??super();
??this.number = number;
??this.banJi = banJi;
??this.name = name;
??this.age = age;
?}
?public int getNumber(){
??return number;
?}
?public int getBanJi(){
??return banJi;
?}
?public int getAge(){
??return age;
?}
?public void setAge(int age){
??this.age = age;
?}
}
?
?
T3:
package Six;
public class B3 {
?public static void main(String[]args){
??String str="第六屆信息技術大賽";
??for(int i=str.length()-1;i>=0;i--)
???System.out.print(str.charAt(i));
??
?}
}
?
?
T4:
package Six;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class B4 {
?public static void main(String[] args) throws IOException {
??File from = new File("D:" + File.separator + "work");
??File to = new File("D:" + File.separator + "test");
??byte[] b = new byte[1024];
??InputStream in;
??OutputStream out;
??File[] files = from.listFiles();
??if (files.length != 0) {
???for (File file : files) {
????if (file.getName().endsWith(".java")) {
?????in = new FileInputStream(file);
?????out = new FileOutputStream(new File(to, file.getName()));
?????while (in.read(b) != -1) {
??????out.write(b);
?????}
?????System.out.println("成功復制文件" + file.getName() + "到"
???????+ to.getName() + "目錄");
?????in.close();
?????out.close();
????}
???}
??} else {
???System.out.println(from.getName() + "目錄下沒有文件");
??}
?}
}
?
?
T5:
package Six;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class B5 {
?public static void main(String[] args) {
??Student student1 = new Student(101344, "鄭永亮", 99);
??Student student2 = new Student(101345, "張三", 89);
??Student student3 = new Student(101346, "李四亮", 79);
??Student student4 = new Student(101347, "王二亮", 69);
??Student student5 = new Student(101348, "劉亮", 9);
??Hashtable<Integer, Student> table = new Hashtable<Integer, Student>();
??table.put(student1.number, student1);
??table.put(student2.number, student2);
??table.put(student3.number, student3);
??table.put(student4.number, student4);
??table.put(student5.number, student5);
??Set<Map.Entry<Integer, Student>> set = table.entrySet();
??Iterator<Map.Entry<Integer, Student>> it = set.iterator();
??while (it.hasNext()) {
???Map.Entry<Integer, Student> entry = it.next();
???System.out.println(entry.getValue());
??}
?}
}
class Student {
?int number;
?String name;
?int score;
?public Student(int number, String name, int score) {
??this.name = name;
??this.number = number;
??this.score = score;
?}
?public String toString() {
??return number + "\t" + name + "\t" + score;
?}
}
?
?
T6:
package Six;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
class B6 {
?public static void main(String[] args) throws ParseException {
??Scanner sc = new Scanner(System.in);
??System.out.print("請輸入一個yyyy-mm-dd格式的日期:");
??String str = sc.nextLine();
??SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
??Date date = sdf.parse(str);
??date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
??System.out.println("明天的日期是:" + sdf.format(date));
?}
}
?
總結
以上是生活随笔為你收集整理的第六届全国信息技术应用水平大赛Java组复赛B卷试题答案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拿不到21.6万年薪退全款,廖雪峰大数据
- 下一篇: 毕设-基于SpringBoot后勤报修系