聯(lián)信永益筆試題目.doc_第1頁
聯(lián)信永益筆試題目.doc_第2頁
聯(lián)信永益筆試題目.doc_第3頁
聯(lián)信永益筆試題目.doc_第4頁
聯(lián)信永益筆試題目.doc_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

聯(lián)信永益筆試題目1. 將一個(gè)整數(shù)的每位數(shù)分解并按逆序放入一個(gè)數(shù)組中(要求用遞歸算法)。參考答案:public class Reversal public static int revertsal(int rs, int i, int num) if (i rs.length) rsi = num % 10; / 將數(shù)字的最后一位放入數(shù)組num = (num - num % 10) / 10; / 去掉最后一個(gè)已放進(jìn)數(shù)組的數(shù)字return revertsal(rs, i + 1, num); / 遞歸調(diào)用 elsereturn 0;public static void main(String args) int num = 1234567890; / 定義一個(gè)整數(shù)String number = num + ; / 將整數(shù)轉(zhuǎn)化為字符串,以便獲得數(shù)字的個(gè)數(shù),是后面的數(shù)組定義大小int rs = new intnumber.length();revertsal(rs, 0, num); / 調(diào)用逆序方法for (int i : rs) System.out.print(i);2. 用1.2.2.3.4.5這六個(gè)數(shù)字,寫出一個(gè)函數(shù),打印出所有不同的排序,如:512234等。要求:”4”不能排在第三位,”3”與”5”不能相連。參考答案:此題有一定難度public class MyTest public static void getNum(char n, int beg, int end) if (beg = end) printNum(String.valueOf(n); else for (int i = beg; i = end; i+) swap(n, beg, i);getNum(n, beg + 1, end);swap(n, beg, i);public static void swap(char n, int x, int y) if (x = y | nx = ny) return;char temp = nx;nx = ny;ny = temp;public static void printNum(String str) if (str.charAt(2) = 4 | str.contains(35) | str.contains(53) return;System.out.println(str);public static void main(String arge) char number = new char 1, 2, 2, 3, 4, 5 ;getNum(number, 0, number.length - 1);3. 求出用1. 2. 5三個(gè)不同個(gè)數(shù)組合的和為100的組合個(gè)數(shù)(如:100個(gè)1是一個(gè)組合,5個(gè)1加19個(gè)5是一個(gè)組合)參考答案1:public class MyTest static int n = 0;public static void main(String arge) for (int i = 1; i = 20; i+) for (int j = 0; j = 0) n += 1;System.out.println(n + 1);參考答案2:public class MyTest int sum = 0;for (int i = 0; i = 20; i+) for (int j = 0; j = 50; j+) for (int n = 0; n = 100; n+) if (5 * i + 2 * j + n = 100) sum+;System.out.println(組合的個(gè)數(shù): + sum);4. 現(xiàn)有如下要求,請(qǐng)根據(jù)需求設(shè)計(jì)表結(jié)構(gòu)并按要求查詢結(jié)果。某學(xué)校需要實(shí)現(xiàn)按班級(jí)和課程查詢學(xué)生成績的功能:(1) 查詢1班所有學(xué)生的數(shù)學(xué)成績。(2) 查詢2班物理成績前10名的學(xué)生。(3) 查詢每個(gè)學(xué)生各課程的成績,返回學(xué)號(hào)、姓名、課程名稱、成績,按學(xué)號(hào)排序。(4) 查詢每個(gè)班的成績參考答案:-創(chuàng)建數(shù)據(jù)庫StudentDBcreate database StudentDBgouse StudentDBgo-創(chuàng)建數(shù)據(jù)表班級(jí)表: T_classcreate table T_class(Class_id varchar(10) primary key,Class_name varchar(20) not null)go-創(chuàng)建數(shù)據(jù)表學(xué)生表: T_studentcreate table T_student(Stud_id varchar(10) primary key,Stud_name varchar(20) not null,Class_id varchar(10) not null)go-創(chuàng)建數(shù)據(jù)表課程表: T_coursecreate table T_course(Course_id varchar(10) primary key,Course_name varchar(100) not null)go-創(chuàng)建數(shù)據(jù)表成績表: T_scorecreate table T_score(Score_id bigint identity(1,1) primary key,Course_id varchar(10) not null,Stud_id varchar(10) not null,Score decimal(5,2)go-創(chuàng)建數(shù)據(jù)表之間的關(guān)系alter table T_studentadd constraint fk_T_student_T_calss_Class_id foreign key (Class_id)references T_class (Class_id)alter table T_scoreadd constraint fk_T_score_T_course_Course_id foreign key (Course_id)references T_course (Course_id)alter table T_scoreadd constraint fk_T_score_T_student_Stud_id foreign key (Stud_id)references T_student (Stud_id)go-查詢班所有學(xué)生的數(shù)學(xué)成績select Stud_name, Scorefrom T_class as cls, T_student as s, T_course as c, T_score as scwhere s.Class_id = cls.Class_id and sc.Stud_id = s.Stud_id and sc.Course_id = c.Course_id and Class_name = 1班 and Course_name = 數(shù)學(xué)-查詢班物理成績前名的學(xué)生select top 10 s.Stud_id, Stud_name, Scorefrom T_class as cls, T_student as s, T_course as c, T_score as scwhere s.Class_id = cls.Class_id and sc.Stud_id = s.Stud_id and sc.Course_id = c.Course_id and Class_name = 2班 and Course_name = 物理order by Score desc-查詢每個(gè)學(xué)生各課程的成績,返回學(xué)號(hào)、姓名、課程名稱、成績,按學(xué)號(hào)排序。select s.Stud_id, Stud_name, Course_name, Scorefrom T_student as s, T_course as c, T_score as scwhere sc.Stud_id = s.Stud_id and sc.Course_id = c.Course_idorder by s.Stud_id asc-查詢每個(gè)班的成績create procedure prc_ScroeClass_name varchar(20)asbeginselect Class_name, Stud_name, Course_name, Scorefrom T_class as cls, T_student as s, T_course as c, T_score as scwhere s.Class_id = cls.Class_id and sc.Stud_id = s.Stud_id and sc.Course_id = c.Course_id and Class_name = Class_nameend1, 編寫程序,實(shí)現(xiàn)九九乘法表。參考答案:package com.csmz.niit;public class JiuJiu public static void main(String args) / 外層循環(huán)for (int i = 1; i = 9; i+) / 內(nèi)層循環(huán)for (int j = 1; j = i; j+) System.out.print(i + * + j + = + i * j + t);System.out.print(n); / 換行2, 定義一個(gè)單鏈表,并將數(shù)字1-100放入單鏈表。參考答案:/ 單鏈表的結(jié)點(diǎn)class SNode private int data; / 數(shù)據(jù)域private SNode next; / 引用域 / 構(gòu)造函數(shù) public SNode(int val, SNode p) data = val; next = p; public int getData() return data;public void setData(int data) this.data = data;public SNode getNext() return next;public void setNext(SNode next) this.next = next;/ 單鏈表class SLinkList private SNode start; /結(jié)點(diǎn)類型的start變量,表示單鏈表的頭結(jié)點(diǎn)(第一個(gè)結(jié)點(diǎn))。 /初始化單鏈表 public SLinkList() start = null; /空的單鏈表,第一個(gè)結(jié)點(diǎn)為null。 /在單鏈表末尾插入一個(gè)新的結(jié)點(diǎn) public void InsertNode(int a) /為新結(jié)點(diǎn)分配內(nèi)存并為數(shù)據(jù)字段分配值 SNode newnode = new SNode(a, null); /如果在空鏈表末尾插入新結(jié)點(diǎn),那么第一個(gè)結(jié)點(diǎn)就是新結(jié)點(diǎn)。 if (start = null) start = newnode; return; /找到鏈表中的最后一個(gè)結(jié)點(diǎn),并將它標(biāo)記為current。 SNode current = start; while (current.getNext() != null) current = current.getNext(); current.setNext(newnode); /使current的next字段指向新結(jié)點(diǎn) newnode.setNext(null) ; /使新結(jié)點(diǎn)next字段指向null / 單鏈表測試類public class TestLinkList public static void main(String args) / 往單鏈表中插入整數(shù) 1 - 100SLinkList slList = new SLinkList();for (int i=1; i=100; i+) slList.InsertNode(i);1 遞歸求1n的和。參考答案:public class MyTest public static int digui(int a) if (a = 0 | a = 1) return a; elsereturn a + digui(a - 1);public static void main(String args) int n = 100;int result = digui(n);System.out.println(result);2 隨機(jī)生成100個(gè)0-99的數(shù)字,統(tǒng)計(jì)0 1 2 3 4 5 6 7 8 9出現(xiàn)的個(gè)數(shù),然后輸出。參考答案:public class MyTest public static void main(String args) int b = new int10;for (int i = 0; i 100; i+) int r = (int) (Math.random() * 100);if (r = 0) br = br + 1;for (int i = 0; i b.length; i+) System.out.println(i + 出現(xiàn)的次數(shù): + bi);3 猴子吃桃問題 (用遞歸算法實(shí)現(xiàn)) 有N個(gè)桃子,猴子第一天吃了所有桃子的一半加一個(gè),第二天又吃了所有桃子一半加一個(gè),到第十天只剩下一個(gè)了, 求N。參考答案:public class MyTest public static int pantao(int n) if (n=3)。參考答案:public class MyTest public static int fibonacci(int n)if (n=2)return n;elsereturn fibonacci(n-1) + fibonacci(n-2);public static void main(String args) int n = 10;System.out.println(f( + n + )= + fibonacci(n);2. 實(shí)現(xiàn)一個(gè)堆棧類Stack,至少包含進(jìn)棧和出棧兩個(gè)方法:Push(int x) 和 int Pop()。參考答案:class Stack private int stck = new int10;private int top; / 棧頂位置/ 初始化棧頂位置為-1,指向一個(gè)空棧。public Stack() top = -1;/ 入棧public void push(int item) if (top = 9)System.out.println(堆棧已滿);elsestck+top = item;/ 出棧public int pop() if (top 0) System.out.println(堆棧為空);return 0; elsereturn stcktop-;public class TestStack public static void main(String args) Stack mystack = new Stack();/ 在堆棧中放入測試數(shù)據(jù)for (int i = 0; i 10; i+)mystack.push(i);/ 出棧System.out.println(Stack in mystack:);for (int i = 0; i 10; i+)System.out.println(mystack.pop();3. 編寫一個(gè)函數(shù),其輸入?yún)?shù)為字符串S,返回值為S中連續(xù)非空格字符所組成的子串中最長子串的長度。參考答案:public class MyTest public static void main(String args) String str = abc 123#$ 789;/ 按空格分隔字符串String arr = str.split( );int lenArray = new int arr.length;/ 取分割后各子串的長度,放入數(shù)組 lenArray 中for (int i = 0; i arr.length; i+) lenArrayi = arri.length();/求子串長度的最大值int maxValue = lenArray0;for (int i = 1; i maxValue) maxValue = lenArrayi;System.out.println(子串中最長子串的長度為: + maxValue);4. 給定一個(gè)整數(shù)序列,編寫代碼計(jì)算出所有子序列和中的最大值。參考答案:此題有難度,可不做。public class MyTest public

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論