一、Java
题目:判断101-200之间有多少个素数,并输出所有素数。
for(int i = 101;i<=200;i++){
int num = 0;
for(int j = 1;j<=i;j++){
if(i%j == 0){
num++;
}
}
if(num == 2){
System.out.println(i);
}
}
二、SQL
Student表的定义
字段名 | 字段描述 | 数据类型 | 主键 | 外键 | 非空 | 唯一 | 自增 |
Id | 学号 | INT(10) | 是 | 否 | 是 | 是 | 是 |
Name | 姓名 | VARCHAR(20) | 否 | 否 | 是 | 否 | 否 |
Sex | 性别 | VARCHAR(4) | 否 | 否 | 否 | 否 | 否 |
Birth | 出生年份 | YEAR | 否 | 否 | 否 | 否 | 否 |
Department | 院系 | VARCHAR(20) | 否 | 否 | 是 | 否 | 否 |
Address | 家庭住址 | VARCHAR(50) | 否 | 否 | 否 | 否 | 否 |
Score表的定义
字段名 | 字段描述 | 数据类型 | 主键 | 外键 | 非空 | 唯一 | 自增 |
Id | 编号 | INT(10) | 是 | 否 | 是 | 是 | 是 |
Stu_id | 学号 | INT(10) | 否 | 否 | 是 | 否 | 否 |
C_name | 课程名 | VARCHAR(20) | 否 | 否 | 否 | 否 | 否 |
Grade | 分数 | INT(10) | 否 | 否 | 否 | 否 | 否 |
Student数据:
Score数据:
-- 查询student表的所有记录
select * from stu
-- 查询student表的第2条到4条记录
select * from stu limit 1,3
-- 从student表查询所有学生的学号(id)、姓名(name)和院系(department)的信息
select id,name,depart from stu
-- 从student表中查询计算机系和英语系的学生的信息
select * from stu where depart in ('计算机系','英语系')
-- 从student表中查询年龄18~22岁的学生信息
select * from stu where NOW()-stu.birth between 18 and 22;
-- 从student表中查询每个院系有多少人
select count(*) from stu GROUP BY depart
-- 从score表中查询每个科目的最高分
select c_name,MAX(grade) from score GROUP BY c_name
-- 查询李四的考试科目(c_name)和考试成绩(grade)
select stu.name,score.c_name,score.grade from stu
left join score
on stu.id = score.stu_id
where stu.name = '李四'
-- 用连接的方式查询所有学生的信息和考试信息
select * from stu
left join score
on stu.id = score.stu_id
-- 计算每个学生的总成绩
select stu.`name`,SUM(score.grade)from stu
left join score
on stu.id = score.stu_id
GROUP BY stu.name
-- 计算每个考试科目的平均成绩
select c_name,AVG(grade) from score
GROUP BY c_name
-- 查询计算机成绩低于95的学生信息
select * from stu
where id in (select stu_id from score where grade < 95 and c_name = '计算机')
-- 查询同时参加计算机和英语考试的学生的信息
select from stu
LEFT JOIN score
on score.stu_id = stu.id
where score.c_name ='计算机' OR score.c_name ='英语'
GROUP BY score.stu_id
having count(score.stu_id)>=2
-- 将计算机考试成绩按从高到低进行排序
select grade from score
where c_name = '计算机'
ORDER BY grade desc
-- 从student表和score表中查询出学生的学号,然后合并查询结果
select id from stu
UNION
select stu_id from score
-- 查询姓张或者姓王的同学的姓名、院系和考试科目及成绩
select stu.name,stu.depart,score.c_name,score.grade from stu
LEFT JOIN score
on stu.id = score.stu_id
where stu.`name` like "张%" or stu.`name` like "王%"
-- 查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩
select stu.name AS '姓名',YEAR(NOW())-stu.birth as '年龄',stu.depart as '院系',score.c_name as '考试科目',score.grade as '成绩'from stu
LEFT JOIN score
on stu.id = score.stu_id
where stu.address like "湖南%"
三、JavaScript编程题
页面上输入一个年份(需验证),判断是否是闰年(能被4整除却不能被100整除的年份;能被400整除的是闰年),需在页面上显示提示信息。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
请输入年龄:<input type="text" id="yearInput">
<button type="button" id="btn" οnclick="fun1()">验证</button>
<script type="text/javascript">
function fun1(){
var year = document.getElementById("yearInput").value;
if(year%400 == 0){
alert("闰年");
}else if(year%4 == 0&&year%100 !=0){
alert("闰年");
}else{
alert("不是闰年");
}
}
</script>
</body>
</html>