Java一點筆試題【2016-04-13】

來源:互聯網
上載者:User

標籤:

第一部分、Java 測試題

1、列舉Java 中八大基礎資料型別 (Elementary Data Type)(8)。

Int 、short、 long、 float、 char、 byte、 double 、boolean

2、依據下面描述建立類、聲明屬性和定義方法,建立類的執行個體對象,調用方法(15)。

建立一個汽車Vehicle類,包括輪胎個數TireNum,汽車顏色Color,車身重量Weight、速度speed等成員變數。並通過不同的構造方法建立執行個體。至少要求:  汽車能夠加速speedUp,減速slowDown,停車stop。

       public  class  Vehicle{

         private int TireNum;

         private String Color;

     private double Weight;

     private int speed;

public Vehicle{

         TireNum = 4;

     Weight = 1000.00;

}

 

Public Vehicle(int TireNum, String Color, double Weight,  int speed){

this. TireNum= TireNum;

this.Color=Color;

this.Weight=Weight;

this.speed=speed;

}

  public int  speedup{

return 1;

}

public int  slowDown{

return 1;

}

 

public int  stop{

return 1;

}

public static void main(string[] args){

Vehicle v = new Vehicle();

v.speedup();

v.shutdown();

v.stop();

}

 

 

}  

 

3、依據下面描述定義介面、類及實現方法,建立類的執行個體對象,調用方法(20)。

建立一個名稱為Vehicle的介面,在介面中添加兩個帶有一個參數的方法start()和stop()。在兩個名稱分別為Bike和Bus的類中實現Vehicle介面。建立一個名稱為Test的類,在Test的main()方法中建立Bike和Bus對象,並訪問start()和stop()方法。

public interface Vehicle(){

public void start(int startnum);

public void stop(int stopnum);

}

public class Bike implement Vehicle(){

 

public void start(int startnum){

System.out.println(“startnumBike:”+startnum);

}

public void stop(int stopnum){

System.out.println(“stopnumBike:”+ stopnum);

}

public static void main(string[] args){

 

}

 

}

public class Bus implement Vehicle(){

 

public void start(int startnum){

System.out.println(“startnumBus:”+startnum);

}

public void stop(int stopnum){

System.out.println(“stopnumBus:”+ stopnum);

}

public static void main(string[] args){

}

 

 

}

public  class Test{

public static void main(String[] args ){

Bike bike = new Bike();

Bus bus = new Bus();

bike.start();

bike.stop();

bus.start();

bus.stop();

}

}

 

 

4、依據如下描述,編程實現檔案內容的讀寫(20)。

將該檔案儲存體到d:\test檔案夾下面,使用IO流將該檔案拷貝到d盤根目錄下。

Import java.io.FileInputStream;

public class IoFile{

         public static void main (String[] args){

         try{

         FilrWrite fw = new FileWriter(“d:/test/Client.java”);

     fw.flush();

fw.close();

         FileInputStream fis = new FileInputStream(“d:/test/Client.java””);

FileOutputStream fis = new FileOutputStream (“d: /Client.java””);

byte[] b = new byte[1024];

while(-1 !=fis.read(b))

{

         Fos.write(b);

}

fos.flush();

fos.close();

fis.close();

}

catch(IOception e){

e.printStackTrace();

}

}

 

}

 

 

5、完成字串String常用操作(7)。

       寫一個方法來檢查輸入的字串是否是迴文(資料對稱)?

 

public class StringReverseDemo {

 public static void main(String[] a) {

  String s = "a man,a plan,a canal, Panama";//給定的字串

  System.out.println(s + " is Palindromes? "+ (isPalindromes(s) == true ? "true" : "false"));

 }

    //判斷是否是迴文

 public static boolean isPalindromes(String s) {

  boolean bool = false;

  String s1 = s.toLowerCase().replaceAll("[\\W\\s]", "");

  char[] c = s1.toCharArray();

  StringBuffer sb = new StringBuffer();

  for (int i = c.length - 1; i >= 0; i--) {

   sb.append(c[i]);

  }

  String s2 = sb.toString();

  if (s1.equals(s2)) {

   bool = true;

  }

  return bool;

 }s

}

 

6、簡要描述Set List區別,ArrayListLinkedList的區別,HashMapHashTable的區別(10)。

 

Set和List都繼承自Collection介面

Set內部元素無順序,List內部元素有順序

 

ArrayList 是順序儲存,LinkedList是鏈式儲存。

 

HashTable同步的,而HashMap是非同步的,效率上比hashTable要高。
HashMap允許空索引值,而HashTable不允許

 

 

 

 

 

 

第二部分、MySQL測試題

7、依據如下需求,完成操作(20)。

資料庫設計:

員工資訊表:

表名

empInfo

中文表名稱

員工資訊

序號

欄位名稱

欄位說明

類型

位元

備忘

1

empID

員工編號

int

4

主鍵

2

empName

員工姓名

varchar

10

 

3

empBirth

出生日期

datetime

 

 

4

DeptID

部門編號

int

4

外鍵

5

empSex

性別

int

1

1:男, 0:女,預設:1

6

empEvaluate

任職評價

varchar

 

預設:‘表現良好’

部門表:

表名

deptInfo

中文表名稱

部門名稱

序號

欄位名稱

欄位說明

類型

位元

備忘

1

DeptID

部門編號

int

4

主鍵

2

DeptName

部門名稱

varchar

50

 

操作說明如下:

  • 建立資料employee
  • 建立資料表(表結構如上,注意主外鍵關係和預設值)
  • 編寫sql句來實現如下功能

l       編寫sql語句向每張表添加至少三條語句

l       查詢女生的人數

l       查詢所有人的資訊(員工標號,員工姓名,部門編號,部門名稱,出生日期,性別)

l       查詢年齡最大的員工資訊(姓名,年齡,部門編號,部門名稱,認知評價)

l       統計90後的人員資訊(姓名,出生日期,性別)

1、create database employee;

2、create table empInfo{

empId int(4) Primary key;

empName varchar(10);

empBirth datetime;

DeptId int(4) reference deptInfo(DddeptID) foreign key;

empSex int(1) enum(1,0)default 1  ;

empEvaluate varchar default ‘表現良好’;

}

Create table deptInfo {

DeptID int(4) primary key;

DeptName varchar(50);

}

3、Insert into empInfo values(1,’name1’,to_date(‘1990-10-10’,’yyyy-mm-ddhh24:mi:ss’),11,1,’可以’);

Insert into empInfo values(2,’name2’,to_date(‘1991-10-10’,’yyyy-mm-ddhh24:mi:ss’),12,0,);

Insert into empInfo values(3,’name3’,to_date(‘1920-10-10’,’yyyy-mm-ddhh24:mi:ss’),13,1,);

 

Insert into deptInfo values(11,’tiyu’);

Insert into deptInfo values(12,’yingyu);

Insert into deptInfo values(13s,’shuxue);

4、select a.empid,a.empname,a.empbirth,a.deptid,a.empsex,b.deptname

From empinfo a join deptinfo b  on a.deptid=b.deptId;

5、select a. empname,sysdate()-a.empbirthas 年齡,a.deptid,a.empevaluate

From empinfo a

Where rownum < 2

Order by empbirth

6、select empname,empbirth,empsex

From empinfo

Where empbirth>=to_date(‘1900-01-01’,’yyyy-mm-ddhh24:mi:ss’)

Java一點筆試題【2016-04-13】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.