# 2017-11-03 周測試題
在 Eclipse 中新建項目,將以下試題完成,時間 60 min。
**注意:格式,命名規范,注釋**
1、實現在控制臺輸出九九乘法表。
~~~
public class Test {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("" + i + " * " + j + " = " + (i * j) + "\t");
}
System.out.println();
}
}
}
~~~
2、定義方法sum,要求實現兩個數之和的運算,要求在main方法中調用。
~~~
public class Test2 {
public static int sum(int a, int b) {
return a + b;
}
public static void main(String[] args) {
int i = 10;
int j = 20;
System.out.println("" + i + " + " + j + " = " + Test2.sum(i, j) + "");
}
}
~~~
3、請寫一個方法打印數組的內容,實現遍歷數組,要求在main方法中調用。
> 提示:在main方法中定義一個數組,然后將數組作為參數傳給方法,在方法中打印結果"[a,b,c,....]"
~~~
public class Test3 {
public static void main(String[] args) {
String[] arr1 = {"a","b","c"};
String[] arr2 = {};
String[] arr3 = null;
System.out.println(printArray(arr1));
System.out.println(printArray(arr2));
System.out.println(printArray(arr3));
}
public static String printArray(String[] arr) {
// [a,b,c]
String result = "";
if (null == arr) {
result = "數組為null";
} else {
if (arr.length == 0) {
result = "數組長度為 0";
} else {
result = "[";
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
result += arr[i];
} else {
result += arr[i] + ",";
}
}
result += "]";
}
}
return result;
}
}
~~~
4、請將消費者在商城購物這個場景抽象出類,并編寫一個客戶端類,實現“小明在歐尚買了一件T恤”這樣一個購物行為。
~~~
public class Customer {
private String name;
public Customer(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
~~~
~~~
public class Market {
private String name;
public Market(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
~~~
~~~
public class Product {
private String name;
public Product(String name) {
super();
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
~~~
~~~
public interface ShoppingServiceInter {
void shopping(Customer cus, Market market, Product product);
}
~~~
~~~
public class ShoppingService implements ShoppingServiceInter {
public void shopping(Customer cus, Market market, Product product) {
System.out.println("" + cus.getName() + "在" + market.getName() + "買了" + product.getName() + "");
}
}
~~~
~~~
public class Client {
public static void main(String[] args) {
Customer tom = new Customer("Tom");
Market ous = new Market("歐尚");
Product tsh = new Product("T恤");
ShoppingServiceInter service = new ShoppingService();
service.shopping(tom, ous, tsh);
}
}
~~~
- 前言
- 計算機概論
- 數據庫
- 數據庫介紹
- MySQL的安裝
- SQL
- 表基本操作
- 修改數據語句
- 數據檢索操作
- 多表數據操作
- 表結構設計
- 綜合應用
- JAVA
- JAVA 介紹
- JAVA 運行原理
- JDK 配置
- 類和對象
- 數據類型
- 變量
- 直接量
- 運算符
- 流程控制
- 數組結構
- 面向對象
- 隱藏和封裝
- 深入構造器
- 類的繼承
- 多態
- 包裝類
- final 修飾符
- 抽象類
- 接口
- 集合框架
- 常用類學習
- 異常處理
- 設計模式-單例模式
- JDBC
- JSP&Servlet
- Web應用
- Tomcat
- JSP
- Scriptlet
- Page 指令
- 包含指令
- 跳轉指令
- 用戶注冊實例
- JSP練習
- 內置對象
- Servlet
- 過濾器
- Web分層思想
- EL表達式
- JSTL
- 分頁實現
- AJAX&JSON
- 開發步驟
- 路徑問題
- Log4j
- 電子書城
- 案例分析
- 核心代碼
- Java 高級
- 文件操作
- 泛型
- 類加載機制和反射
- 注解 Annotation
- Mybatis框架
- 框架介紹
- Mybatis簡單實現
- 表基本操作
- 優化配置文件
- 表字段名與實體類屬性名不同的解決方案
- 一對一關聯
- 一對多關聯
- 教學管理
- 學員名錄
- 周測統計
- 2017-10-27
- 2017-11-03
- 2017-11-10
- 2017-11-17
- 課堂作業
- 班會紀要
- 2017-10-24
- 缺勤記錄
- 班級備忘錄
- 違紀統計
- 編程素養
- Day001
- Day002
- Day003
- Day004
- Day005
- Day006
- Day007
- Day008
- Day009
- Day010
- Day011
- Day012
- Day013
- Day014
- Day015
- Day016
- Day017
- Day018
- Day019