一、JavaScript 编程题
输入某年某月某日,判断这一天是这一年的第几天?
解答:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>判断第几天</title>
<style type="text/css">
</style>
</head>
<body>
<div id="container">
<form>
<input type="text" id="inputContent" placeholder="请输入xxx年xxx月xxx日"/>
<input type="button" onclick="getResult()" value="确认" />
</form>
<p id="showResult">展示计算结果</p>
</div>
</body>
<script type="text/javascript">
function getResult(){
// 获取输入内容。
var inputStr = document.getElementById("inputContent").value;
// 分界点。
var y = inputStr.valueOf("年");
var m = inputStr.valueOf("月");
var d = inputStr.valueOf("日");
// 获取年月日。
var y1 = parseInt(inputStr.substring(0,y));
var m1 = parseInt(inputStr.substring(y+1,m);
var d1 = parseInt(inputStr.substring(m+1,d);
// 获取毫秒数。
var second1 = new Date(y1,m1-1,d1); // 月(0-11)、日(1-30)
var second2 = new Date(y1,0,0);
// 计算间隔天数。
var dayInterval = (second1 - second2)/(24*60*60*1000);
// 输出结果。
document.getElementById("showResult").innerHTML = dayInterval;
}
</script>
</html>
二、MySQL 编程题
在名为商品库的数据库中包含有商品规格表 Content 和商品特性表 Property,它们的定义分别为:
Content(Code varchar(50),Class varchar(20),Price double,Number int)
Property(Code varchar(50),Place varchar(20),Brand varchar(50))
(1)写出下面查询语句的作用;
SELECT Distinct Brand FROM Property;
解答:
查询所有商品的去除重复后的商标。
(2)从商品规格表中查询出每类商品的最高单价
解答:
select class,max(Price) as '该类商品的最高单价' from Content
group by class;
(3) 从商品规格表中查询出同一类商品多于一种的所有分类名
解答:
select class from Content
group by class having count(*) > 1;
三、Java 编程题
打印出如下图案(菱形) 。
public class Day10{
public static void main(String[] args){
Day10 rhombus = new Day10();
// 本方法只适用于奇数。
rhombus.getResult(7);
}
/**
* 观察:
* 1. 每行数量:1,3,5,7,5,3,1。
* 2. 起始位置:3,2,1,0,3,2,1。
* 3. 行分界点:row/2。
* 思路:
* 1. 每行数量得:前,2*i + 1。后,2*(row-i-1) + 1。
* 2. 起始位置得:从起始位置加入多个“*”。即列考虑到row/2即可。
*/
public void getResult(int row){
// 行操作。
for(int i = 0; i < row; i++){
// 列操作。
for(int j = 0; j <= row/2; j++){ //
// 判断起始位置:Math.abs(row/2 - i) == j。
if(Math.abs(row/2 - i) == j){
// 判断行分界点:row/2
if(i <= row/2){
// 输出相应数量的“*”
for(int g = 0; g < (2 * i + 1); g++){
System.out.println("*");
}
}else{
// 输出相应数量的“*”
for(int g = 0; g < (2 * (row - i-1) + 1); g++){
System.out.println("*");
}
}
}else{
System.out.print(" "); //不满足加空格。
}
}
System.out.println();
}
}
}