700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 第六届全国信息技术应用水平大赛Java组复赛B卷试题答案

第六届全国信息技术应用水平大赛Java组复赛B卷试题答案

时间:2022-03-07 20:42:27

相关推荐

第六届全国信息技术应用水平大赛Java组复赛B卷试题答案

1、九九乘法口诀表是学习算数乘法的基础,用一个for循环编程实现并显示九九乘法口诀表,程序运行显示结果如下所示。(25分)

1*1=1

1*2=22*2=4

1*3=32*3=63*3=9

1*4=42*4=83*4=124*4=16

1*5=52*5=103*5=154*5=205*5=25

1*6=62*6=123*6=184*6=245*6=306*6=36

1*7=72*7=143*7=214*7=285*7=356*7=427*7=49

1*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=64

1*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*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));

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。