中文字幕在线一区二区在线,久久久精品免费观看国产,无码日日模日日碰夜夜爽,天堂av在线最新版在线,日韩美精品无码一本二本三本,麻豆精品三级国产国语,精品无码AⅤ片,国产区在线观看视频

      華為Java機試題

      時間:2024-09-04 04:25:34 SUN認證 我要投稿
      • 相關推薦

      2017年華為Java機試題錦集

        Java對程序提供了安全管理器,防止程序的非法訪問。下面是小編收集的華為Java機試題,希望大家認真閱讀!

      2017年華為Java機試題錦集

        1.程序實現目標: 輸入一個字符串,將其各個字符對應的ASCII值加5后,輸出結果。

        程序要求:該字符串只包含小寫字母,若其值加5后的字符值大于'z',將其轉換成從a開始的字符。

        package com.xcbeyond;

        /**

        * @author xcbeyond

        * 2015-5-7下午10:37:43

        * 1.程序實現目標: 輸入一個字符串,將其各個字符對應的ASCII值加5后,輸出結果。

        * 程序要求:該字符串只包含小寫字母,若其值加5后的字符值大于'z',將其轉換成從a開始的字符。

        */

        public class StringParseASCII {

        public static void main(String[] args) {

        System.out.print(stringParseASCII("abx"));

        }

        public static String stringParseASCII(String str){

        StringBuffer result = new StringBuffer();

        char tmp;

        for(int i = 0;i

        tmp = (char)(str.charAt(i)+5);

        if(tmp > 'z') {

        result.append('a');

        }else {

        result.append(tmp);

        }

        }

        return result.toString();

        }

        }

        2.程序實現目標:求一個整型數組中元素的平均值,并統計其中大于和小于此平均值的元素的個數。

        程序要求:輸入:整型數組中的元素個數及各個元素。

        輸出:整型數組中元素的平均值,大于和小于此平均值的元素的個數。

        package com.xcbeyond;

        import java.util.Arrays;

        /**

        *

        * @author xcbeyond

        * 2015-5-7下午11:06:29

        *2.程序實現目標:求一個整型數組中元素的平均值,并統計其中大于和小于此平均值的元素的個數。

        *程序要求:

        * 輸入:整型數組中的元素個數及各個元素。

        * 輸出:整型數組中元素的平均值,大于和小于此平均值的元素的個數。

        */

        public class CountAvg {

        public static void main(String[] args) {

        int[] array = {1,23,4,13,6};

        System.out.println(Arrays.toString(array)+"的平均值:"+avg(array)+"\n" +

        "大于和小于平均值元素的個數分別為:"+Arrays.toString(countAvg(array)));

        }

        public static int[] countAvg(int[] array) {

        int gt = 0; //grater than

        int lt = 0; //less than

        int[] result = {0,0};

        int average = avg(array);

        for(int i = 0;i

        if(array[i]>average) {

        gt++;

        }else if(array[i]

        lt++;

        }

        }

        result[0] = gt;

        result[1] = lt;

        return result;

        }

        /**

        * average

        * @param array

        * @return

        */

        public static int avg(int[] array) {

        int average = 0;

        int sum = 0;

        for(int i = 0 ;i

        sum += array[i];

        }

        average = sum/array.length;

        return average;

        }

        }

        3、手動輸入一個存儲整數的數組,要求輸出數組里面的2個最大值。

        實例:

        輸入:1,2,5,9,84,3,2

        輸出:84,9

        package com.xcbeyond;

        import java.util.Arrays;

        /**

        * @author xcbeyond

        * 2015-5-7下午11:35:13

        *3、手動輸入一個存儲整數的數組,要求輸出數組里面的2個最大值。

        * 實例:

        * 輸入:1,2,5,9,84,3,2

        * 輸出:84,9

        */

        public class FindMaxTwoNum {

        public static void main(String[] args) {

        int[] array = {1,2,5,9,84,3,2};

        System.out.println("數組"+Arrays.toString(array)+"里面最大的2個數為:");

        findMaxTwoNum(array);

         //方法二:

        //

         }

        public static void findMaxTwoNum(int[] array) {

        int[] result = {0,0};

        for(int i = 0 ;i

        for(int j = 0;j

        if(array[j]

        int tmp;

        tmp = array[j];

        array[j] = array[j+1];

        array[j+1] = tmp;

        }

        }

        }

        System.out.println(array[0]+"、"+array[1]);

        }

        }

        4、回文數字判斷。

        題目描述:

        有這樣一類數字,他們順著看和倒著看是相同的數,例如:121,656,2332等,這樣的數字就稱為:回文數字。編寫一個函數,判斷某數字是否是回文數字。

        要求實現方法:

        public String isPalindrome(String strIn);

        【輸入】strIn: 整數,以字符串表示;

        【返回】true: 是回文數字;

        false: 不是回文數字;

        【注意】只需要完成該函數功能算法,中間不需要有任何IO的輸入輸出

        package com.xcbeyond;

        import java.util.Scanner;

        /**

        * @author xcbeyond

        * 2015-5-10下午03:46:56

        *4、回文數字判斷。

        *題目描述:

        * 有這樣一類數字,他們順著看和倒著看是相同的數,例如:121,656,2332等,這樣的數字就稱為:

        * 回文數字。編寫一個函數,判斷某數字是否是回文數字。

        */

        public class IsPalindrome {

        public static void main(String[] args) {

        System.out.print("請輸入一個回文數字:");

        Scanner console = new Scanner(System.in);

        String numStr = console.nextLine();

        if(isPalindrome(numStr)) {

        System.out.println(numStr+"是回文數字!");

        }else{

        System.out.println(numStr+"不是回文數字!");

        }

        }

        public static boolean isPalindrome(String str){

        boolean result = false;

        for(int i = 0 ;i

        if(str.charAt(i) == str.charAt(str.length()-1-i)) {

        result = true;

        }

        }

        return result;

        }

        }

        5、要求:隨機打印50個隨機(4-10長度)的字符串,要求字符串包含的范圍是所有的英文字母包含大小寫和數字,按照編碼順序排序,每行打印4個,要求首字符對齊

        package com.xcbeyond;

        import java.util.HashSet;

        import java.util.Set;

        /**

        *

        * @author xcbeyond

        * 2015-5-10下午04:05:42

        *5、要求:隨機打印50個隨機(4-10長度)的字符串,要求字符串包含的范圍是

        * 所有的英文字母包含大小寫和數字,按照編碼順序排序,每行打印4個,要求首字符對齊

        */

        public class RandomStr {

        public static void main(String[] args) {

        Set setStr = new HashSet();

        for(int i = 0 ;i<50;i++) {

        setStr.add(randomStr(5));

        }

        int count = 1;

        for(String i:setStr){

        System.out.print(i+" ");

        if(count%4 == 0) {

        System.out.println();

        }

        count++;

        }

        }

        /**

        * @param strLen:隨機字符串的長度

        */

        public static String randomStr(int strLen) {

        char[] str = new char[strLen];

        int i = 0;

        while(i

        int f = (int)Math.random()*3;

        if(f == 0) {

        str[i] = (char)('a' + Math.random()*26);

        }else if(f == 1) {

        str[i] = (char)('A' + Math.random()*26);

        }else {

        str[i] = (char)('0' + Math.random()*10);

        }

        i++;

        }

        return new String(str);

        }

        }

        6.手動輸入一個字符串,僅限小寫字母,統計并輸出每個字符在字符串中出現的次數,并輸出。提示(可以用Map)

        實例:

        輸入:aaabbbccc

        輸出:a 3

        b 3

        c 3

        package com.xcbeyond;

        import java.util.HashMap;

        import java.util.Map;

        /**

        *

        * @author xcbeyond

        * 2015-5-10下午04:47:45

        * 6.手動輸入一個字符串,僅限小寫字母,統計并輸出每個字符在字符串中出現的次數,并輸出。

        * 提示(可以用Map)

        * 實例:

        * 輸入:aaabbbccc

        * 輸出: a 3

        * b 3

        * c 3

        */

        public class GetCharCount {

        public static void main(String[] args) {

        String str = "aaabbbrcc";

        String reg = "^[a-z]*$";

        if (str.matches(reg)) {

        Map map = getCharCount(str);

        for (Map.Entry e : map.entrySet()) {

        System.out.println(e.getKey() + ": " + e.getValue());

        }

        }else {

        System.out.println("輸入的字符不合法,不是小寫字母");

        }

        }

        public static Map getCharCount(String str) {

        Map map = new HashMap();

        char[] arr = str.toCharArray();

        for(int i = 0;i

        if(!map.containsKey(arr[i])) {

        map.put(arr[i], new Integer(1));

        }else {

        map.put(arr[i],map.get(arr[i])+1);

        }

        }

        return map;

        }

        }

        7、要求實現方法public String addTwoBigNumber(String s1,string s2)

        大數相加,注意處理異常

        public class Test{

        public String addTwoBigNumber(String s1,string s2)

        {

        return "";

        }

        public static void main(String[] args)

        {

        Test test = new Test();

        test.addTwoBigNumber("123456789","987654321")

        }

        }

        8、比較二維數組列最小值,組成一個新數組返回。(實現核心算法,不需要使用IO)

        輸入:intArr = {{5,6,1,16},{7,3,9}}

        輸出:intArrs ={1,3}

        package com.xcbeyond;

        import java.util.Arrays;

        /**

        * @author xcbeyond

        * 2015-5-10下午09:09:20

        *8、比較二維數組列最小值,組成一個新數組返回。(實現核心算法,不需要使用IO)

        * 輸入:intArr = {{5,6,1,16},{7,3,9}}

        * 輸出:intArrs ={1,3}

        */

        public class GetColMin {

        public static void main(String[] args) {

        int[][] arr = {{5,6,1,16},{7,3,9}};

        System.out.println(Arrays.toString(getColMin(arr)));

        }

        public static int[] getColMin(int[][] arr) {

        int[] minArr = new int[arr.length];

        for(int i = 0;i

        int[] tmp = arr[i];

        Arrays.sort(tmp);

        minArr[i] = tmp[0];

        }

        return minArr;

        }

        }

        9. 輸入:a aa,cat tiger.123dd

        輸出: tiger

        功能描述:鍵盤輸入一句話

        輸出一句話中最常的單詞,如果最長的出現多次,返回第一個。

        這句話只包含數字字母和標點。

        package com.xcbeyond;

        import java.util.ArrayList;

        import java.util.Scanner;

        /**

        *

        * @author xcbeyond

        * 2015-5-10下午09:45:03

        *9. 輸入:a aa,cat tiger.123dd

        * 輸出: tiger

        * 功能描述:鍵盤輸入一句話

        * 輸出一句話中最常的單詞,如果最長的出現多次,返回第一個。

        * 這句話只包含數字字母和標點。

        */

        public class GetLongString {

        public static void main(String[] args) {

        System.out.println("請輸入一句話:");

        Scanner console = new Scanner(System.in);

        String str = console.nextLine();

        System.out.println("最長的單詞為:"+getLongString(str));

        }

        public static String getLongString(String str) {

        String[] wordStr = str.split("[ ,.0-9]");

        int sum = 0;

        ArrayList result = new ArrayList();

        for(int i = 0;i

        if(sum

        sum = wordStr[i].length();

        result.add(wordStr[i]);

        }

        }

        return result.get(result.size()-1);

        }

        }

        10. 功能描述:將字符串中的字母全部替換成字母的下一個字母,

        要是最后一位是z或Z則替換為a或A。

        輸入:aBxyZ

        輸出:bCyzA

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * 2015-5-10下午10:11:02

        *10. 功能描述:

        * 將字符串中的字母全部替換成字母的下一個字母,要是最后一位是z或Z則替換為a或A。

        * 輸入:aBxyZ

        * 輸出:bCyzA

        */

        public class NextString {

        public static void main(String[] args) {

        String str = "aBxyZ";

        System.out.println(nextString(str));

        }

        public static String nextString(String str) {

        String result = "";

        char[] arr = str.toCharArray();

        for(int i = 0;i

        if(arr[i] == 'z' || arr[i] == 'Z') {

        arr[i] = (char)(arr[i]-25);

        }else if(arr[i]<='z'&&arr[i]>='a' || arr[i]<='Z'&&arr[i]>='A') {

        arr[i] = (char)(arr[i]+1);

        }

        }

        return String.valueOf(arr);

        }

        }

        11. 功能描述:判斷一個字符串中是否只含有相同的子字符串(子串長度>=2)

        輸入:abab

        返回:true

        輸入:abcd

        返回:false

        要求實現方法:

        public boolean checkString(String data)

        {

        //TODO

        return false;

        }

        12. 功能描述:已知:yi er san si wu liu qi ba jiu 分別對應123456789,

        對一段只含有這幾種字符串的字符串進行轉換,如:

        輸入:yiersansan

        輸出:1233

        要求實現方法:

        public String trunNumber(String data)

        {

        //TODO

        return "";

        }

        13. 功能描述:刪除字符串中字符個數最少的字符,最少字符串有多個,最少的要全部刪除

        然后返回該子字符串。

        輸入:asdasdas

        輸出:asasas

        package com.xcbeyond;

        import java.util.ArrayList;

        import java.util.Collections;

        import java.util.Comparator;

        import java.util.HashMap;

        import java.util.List;

        import java.util.Map;

        import java.util.Map.Entry;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/11 13:16:06

        */

        public class DeleteLittle {

        public static void main(String[] args) {

        String str = "asdasdas";

        System.out.println(deleteLittle(str));

        }

        public static String deleteLittle(String str) {

        Map map = new HashMap();

        char[] ch = str.toCharArray();

        for(int i = 0;i

        if(!map.containsKey(ch[i])){

        map.put(ch[i], 1);

        }else {

        map.put(ch[i], map.get(ch[i])+1);

        }

        }

        List> list = new ArrayList>(map.entrySet());

        Collections.sort(list, new Comparator>(){

        @Override

        public int compare(Entry o1,

        Entry o2) {

        return o1.getValue().compareTo(o2.getValue());

        }

        });

        String[] s = str.split(list.get(0).getKey().toString());

        StringBuffer sb = new StringBuffer();

        for(int i = 0;i

        sb.append(s[i]);

        }

        return sb.toString();

        }

        }

        14. 功能描述:找出一個int[]中滿足 2^n的數字,然后組成的新的數組

        輸入:{4,3,8}

        輸出:{4,8}

        package com.xcbeyond;

        import java.util.ArrayList;

        import java.util.Arrays;

        import java.util.List;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/11 14:04:43

        */

        public class NextString {

        public static void main(String[] args) {

        int[] arr = {4,3,8};

        System.out.println(Arrays.toString(nextString(arr)));

        }

        public static int[] nextString(int[] arr) {

        List list = new ArrayList();

        for(int i = 0;i

        int tmp = arr[i];

        while(tmp != 2) {

        if(tmp%2==0) {

        tmp = tmp/2;

        }else{

        break;

        }

        }

        if(tmp == 2) {

        list.add(arr[i]);

        }

        }

        int[] resultArr = new int[list.size()];

        for(int i = 0;i

        resultArr[i] = list.get(i);

        }

        return resultArr;

        }

        }

        15.

        功能描述:共data1個人,圍成一圈,然后標號,從1-data1。

        然后從data2號開始從1報數,報3的出列,求出列序列。

        返回一個數組

        如:

        輸入:3,2

        輸出:1,2,3

        要求實現方法:

        /**

        * data1:人數

        * data2 : 起始位置

        *

        */

        public int[] circleOut(int data1,int data2)

        {

        int outNum = 3;

        //TODO

        return null;

        }

        16. 功能描述:統計一個數字轉為二進制后,0和1的個數,組成數組返回

        輸入:6

        輸出:{1,2}

        package com.xcbeyond;

        import java.util.Arrays;

        import java.util.HashMap;

        import java.util.Map;

        /**

        * @author xcbeyond

        * @date 2015/05/11 14:32:46

        */

        public class IntParseBinary {

        public static void main(String[] args) {

        int data = 6;

        System.out.println(Arrays.toString(getNumber(data)));

        }

        public static int[] getNumber(int data) {

        char[] binaryStr = Integer.toBinaryString(data).toCharArray();

        Map map = new HashMap();

        for(int i = 0;i

        if(!map.containsKey(binaryStr[i])) {

        map.put(binaryStr[i], 1);

        }else{

        map.put(binaryStr[i], map.get(binaryStr[i])+1);

        }

        }

        return new int[]{map.get('0'),map.get('1')};

        }

        }

        17. 功能描述:對一個二進制數的每位進行0和1反轉,求翻轉后的二進制所對應的十進制

        輸入:1010

        輸出:5

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/11 15:01:03

        */

        public class BitReverse {

        public static void main(String[] args) {

        String data = "1010";

        System.out.println(getNumber(data));

        }

        public static String getNumber(String data){

        char[] dataStr = data.toCharArray();

        for(int i = 0;i

        if(dataStr[i] == '0') {

        dataStr[i] = '1';

        }else {

        dataStr[i] = '0';

        }

        }

        String str = "";

        for(int i = 0 ;i

        str += dataStr[i];

        }

        String res = Integer.valueOf(str, 2).toString();

        return res;

        }

        }

        18. 功能描述:判斷一個字符串中的"( )"是否配對

        輸入:if(a.equals(a))

        輸出:true

        package com.xcbeyond;

        /**

        * @author xcbeyond

        * @date 2015/05/11 15:50:39

        */

        public class IsMatch {

        public static void main(String[] args) {

        String str = "if(a.equals(a))";

        System.out.println(isMatch(str));

        }

        public static boolean isMatch(String str){

        boolean isMatch = false;

        char[] ch = str.toCharArray();

        int count = 0;

        for(int i = 0 ;i

        if(ch[i] == '(') {

        count++;

        }else if(ch[i] == ')') {

        count--;

        }

        }

        if(count == 0) {

        isMatch = true;

        }

        return isMatch;

        }

        }

        19. 功能描述:查找一個字符串的子字符串集

        輸入:abab

        輸出:a b ab ba aba bab

        要求實現方法:

        public List getChildren(String data)

        {

        List list = new ArrayList();

        //TODO

        return list;

        }

        20. 功能描述:數組的循環移位,

        輸入:{a,b,c},2

        輸出:{b,c,a}

        要求實現方法:

        /**

        *data :待循環數組

        *index:移動位數

        */

        public String[] getChildren(String[] data,int index)

        {

        //TODO

        return null;

        }

        package com.xcbeyond;

        import java.util.Arrays;

        /**

        * @author xcbeyond

        * @date 2015/05/12 9:16:56

        */

        public class Demo20 {

        public static void main(String[] args) {

        String[] data = {"a","b","c"};

        System.out.println(Arrays.toString(getChildren(data,2)));

        }

        public static String[] getChildren(String[] data,int index){

        String[] resData = new String[data.length];

        for(int i = 0;i

        resData[i] = data[index-1+i];

        }

        resData[resData.length-1] = data[0];

        return resData;

        }

        }

        21. 程序實現目標: 輸入一個字符,將字符轉換為小寫,將其對應的ASCII值加5后,輸出結果。

        程序要求:若其值加5后的字符值大于'z',將其轉換成從a開始的字符。

        輸入:‘A’

        輸出:‘f’

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 9:31:45

        */

        public class Demo21 {

        public static void main(String[] args) {

        System.out.println(parseChar('X'));

        }

        public static char parseChar(char ch) {

        char resCh = 'a';

        resCh = (char)(Character.toLowerCase(ch) + 5);

        if(resCh > 'z') {

        resCh = (char)(resCh - 26);

        }

        return resCh;

        }

        }

        22. 要求:將一個二維數組進行逆序,逆序后所有的元素行列不定,進行隨機排列

        ①先把數組每一行逆序

        ②再把逆序后每一行進行隨機排列

        如:{{4,3,32,5},{1,2,3,4},{9,6,5,4}};

        �6�04 6 5 9

        3 4 2 1

        5 4 32 3

        package com.xcbeyond;

        import java.util.Random;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 9:55:26

        */

        public class Demo22 {

        public static void main(String[] args) {

        int[][] arr = {{4,3,32,5},{1,2,3,4},{9,6,5,4}};

        int[][] arr2 = arrRandomReverse(arr);

        for(int i = 0;i

        for(int j = 0;j

        System.out.print(arr2[i][j]+" ");

        }

        System.out.println();

        }

        }

        public static int[][] arrRandomReverse(int[][] arr) {

        int[][] resArr = new int[arr.length][];

        for(int i = 0 ;i

        resArr[arr.length-1-i] = arr[i];

        }

        Random r = new Random();

        for(int i = 0 ;i

        for(int j = 0;j

        int p = r.nextInt(resArr[i].length);

        int tmp;

        tmp = resArr[i][j];

        resArr[i][j] = resArr[i][p];

        resArr[i][p] = tmp;

        }

        }

        return resArr;

        }

        }

        23. 根據輸入m數據,找出str的m個字符的所有字符串

        例如"abc" m=2

        "ab" "ac" "bc"

        "abcd" m=3

        "abc" "acd" "bcd" "abd"

        public ArrayList perenum(String str,int m)

        {

        return null;

        }

        24. 分解質因數

        eg:輸入 28

        輸出 2*2*7

        25.n個長度的字符串中取m個長度的組合

        26. 二維數組轉置

        例:1 2 3

        4 5 6

        轉置

        1 4

        2 5

        3 6

        package com.xcbeyond;

        /**

        * @author xcbeyond

        * @date 2015/05/12 10:56:04

        */

        public class Demo26 {

        public static void main(String[] args) {

        int[][] arr = {{4,3,32,5},{1,2,3,4},{9,6,5,4}};

        int[][] arr2 = arrayReverse(arr);

        for(int i = 0;i

        for(int j = 0;j

        System.out.print(arr2[i][j]+" ");

        }

        System.out.println();

        }

        }

        public static int[][] arrayReverse(int[][] arr) {

        int[][] resArr = new int[arr[0].length][arr.length];

        for(int i = 0;i

        for(int j = 0;j

        resArr[i][j] = arr[j][i];

        }

        }

        return resArr;

        }

        }

        27. 功能描述:輸入字符串,將該字符串中數字放到非數字的后面,并保持原有順序不變。

        例如:h3a2p0p1y----------happy3201

        public String childStr(String inputStr){

        }

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 11:02:27

        */

        public class Demo27 {

        public static void main(String[] args) {

        String str = "h3a2p0p1y";

        System.out.println(childStr(str));

        }

        public static String childStr(String inputStr){

        String numStr = "";

        String str = "";

        String numRegex = "[0-9]";

        String strRegex = "[a-zA-Z]";

        for(int i = 0;i

        if((inputStr.charAt(i)+"").matches(numRegex)) {

        numStr += inputStr.charAt(i);

        }else if((inputStr.charAt(i)+"").matches(strRegex)) {

        str += inputStr.charAt(i);

        }

        }

        return str+numStr;

        }

        }

        28. 輸入一個身份證號碼(15位和18位)和一個年份,計算現在的年齡(忽略非法參數)

        eg:610618199001020065 2011

        輸出:21

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 11:14:56

        */

        public class Demo28 {

        public static void main(String[] args) {

        String id = "610618199001020065";

        System.out.println(countAge(id,2011));

        }

        public static int countAge(String ID,int date) {

        String birthDate = "";

        if(ID.length() == 15) {

        birthDate = ID.substring(3, 7);

        }else if(ID.length() == 18) {

        birthDate = ID.substring(6, 10);

        }

        int age = 0;

        age = date - Integer.parseInt(birthDate);

        return age;

        }

        }

        29. 輸入一個字符串,如果是小寫則轉換成相應的大寫字母的后五位,如果是VWXYZ則轉換成abcde,其他的都不變,例如:“aDsR154+-/.”則應該輸出為“FDXR154+-/.”

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 13:39:20

        */

        public class Demo29 {

        public static void main(String[] args) {

        String str = "aDsR154+-/.";

        System.out.println(parseStr(str));

        }

        public static String parseStr(String str) {

        StringBuffer sb = new StringBuffer();

        char tmp;

        for(int i = 0;i

        if(str.charAt(i)>='a' && str.charAt(i)<='z') {

        tmp =(char)(Character.toUpperCase(str.charAt(i))+5);

        if(tmp > 'Z') {

        tmp = (char)(tmp - 26);

        }

        sb.append(tmp);

        }else {

        sb.append(str.charAt(i));

        }

        }

        return sb.toString();

        }

        }

        30. 字母轉換(完成給出類中的方法):

        要求:

        1、傳入大寫字母,返回小寫字母。

        2、返回的小寫字母應為該大寫字母對應的小寫字母后第五個小寫字母,

        例:出入'A',則返回f.

        3、若按2中的要求返回的字母超過z,則超過1返回a,超過2返回b,依次類推;

        public class test{

        public static void main(String[] args)

        {

        //可寫測試代碼

        }

        //需要完成的方法

        public char upperToLower(char upperCase)

        {

        //完成代碼

        }

        }

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 14:05:49

        */

        public class Demo30 {

        public static void main(String[] args) {

        char ch = 'A';

        System.out.println(upperToLower(ch));

        }

        public static char upperToLower(char upperCase) {

        char resCh = 'a';

        resCh = (char)(Character.toLowerCase(upperCase) + 5);

        if(resCh > 'z') {

        resCh = (char)(resCh - 26);

        }

        return resCh;

        }

        }

        31. 刪除一個字符串里出現次數最多的子字符串

        如果有多個出現次數相同的并且出現次數最多則將多個全部刪除比如abbccd得到結果 ad

        32. 判斷字符串首字母就大寫,非首字母小寫

        1、如輸入 Good 返回 TRUE

        2、過程中不需要輸出任何IO流。

        33. 將一個英文語句以單詞為單位逆序排放。例如“I am a boy”,逆序排放后為“boy a am I”

        所有單詞之間用一個空格隔開,語句中除了英文字母外,不再包含其他字符

        接口說明

        /**

        * 反轉句子

        *

        * @param sentence 原句子

        * @return 反轉后的句子

        */

        public String reverse(String sentence);

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 14:23:12

        */

        public class Demo33 {

        public static void main(String[] args) {

        String str = "I am a boy";

        System.out.println(reverse(str));

        }

        public static String reverse(String sentence) {

        String regex = "[ *]";

        String[] ch = sentence.split(regex);

        StringBuffer sb = new StringBuffer();

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

        sb.append(ch[i]+" ");

        }

        return sb.toString();

        }

        }

        34. 題目背景

        寫出一個程序,接受一個浮點數值,輸出該數值的近似整數值。如果小數點后數值大于等于5,向上取整;小于5,則向下取整

        接口

        int round(double d)

        舉例

        -4.5 四舍五入的結果是-4

        4.4 四舍五入的結果是4

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 14:32:50

        */

        public class Demo34 {

        public static void main(String[] args) {

        double d = 3.65;

        System.out.println(round(d));

        }

        public static int round(double d) {

        String str = Double.toString(d);

        String subStr = str.substring(str.indexOf('.')+1, str.indexOf('.')+2);

        int a = Integer.parseInt(subStr);

        int res = 0;

        if(a <5) {

        res = (int)Math.floor(d);

        }else {

        res = (int)Math.ceil(d);

        }

        return res;

        }

        }

        35.數列求和

        編寫程序,輸入一個正整數n,求下列算式的值。要求定義和調用函數fact(k)計算k的階乘,函數返回值的類型是double。

        1+1/2!+ .... +1/n!

        輸出保留5位小數。

        下面是一些合理的表達式的例子:

        Input 5

        Output 1.71667

        package com.xcbeyond;

        public class Demo35 {

        public static void main(String[] args) {

        System.out.println(resutl(5));

        }

        public static double resutl(int n) {

        double res = 0.0;

        int i = 1;

        while(i<=n) {

        res += (double)1.0/fack(i);

        i++;

        }

        return res;

        }

        public static int fack(int k) {

        int result = 0;

        if(k == 1) {

        result = 1;

        }else {

        result = fack(k-1)*k;

        }

        return result;

        }

        }

        36. 計算整數各個數位之和

        描述: 要求使用遞歸實現,計算整數各個數位之和。

        舉例: 123 --> 1+2+3 = 6

        運行時間限制: 無限制

        內存限制: 無限制

        輸入: 0xff ff ff ff以內的整數

        輸出: NA

        樣例輸入: 123

        樣例輸出: 6

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 15:23:16

        */

        public class Demo36 {

        public static void main(String[] args) {

        int num = 123;

        System.out.println(bitSum(num));

        }

        public static int bitSum(int num) {

        int res = 0;

        if(num<10) {

        res = num;

        }else {

        res = num%10 + bitSum(num/10);

        }

        return res;

        }

        }

        37.提取不重復的整數

        描述: 輸入一個int型32位整數,按照從右向左的閱讀順序,返回一個不含重復數字的新的整數。

        運行時間限制: 10 Sec

        內存限制: 無限制

        輸入: 整數,如9876673

        注意:

        1、整數最后的0,請忽略,例如:輸入1750,輸出:571

        2、負數,保留'-'在前面,例如:輸入-175,輸出:-571

        輸出: 整數,如37689

        樣例輸入: 9876673

        樣例輸出: 37689

        package com.xcbeyond;

        /**

        *

        * @author xcbeyond

        * @date 2015/05/12 15:50:34

        */

        public class Demo37 {

        public static void main(String[] args) {

        int num = -12310;

        System.out.println(getConvertInt(num));

        }

        public static int getConvertInt(int num) {

        String str = String.valueOf(num);

        StringBuffer sb = new StringBuffer();

        boolean flg = true;

        if(str.charAt(0) == '-') {

        flg = false;

        sb.append(str.charAt(0));

        }

        if(str.charAt(str.length()-1) != '0') {

        sb.append(str.charAt(str.length()-1));

        }

        for(int i = str.length()-2;i>0;i--) {

        sb.append(str.charAt(i));

        }

        if(flg) {

        sb.append(str.charAt(0));

        }

        return Integer.parseInt(sb.toString());

        }

        }

      【華為Java機試題】相關文章:

      華為JAVA考試試題11-01

      華為Java面試題精選10-13

      華為Java上機考試題07-04

      2016年華為機試題及答案07-23

      華為上機試題匯總09-20

      華為筆試題及答案11-01

      華為認證最新試題及答案08-28

      華為認證筆試題大全08-15

      JAVA模擬試題及答案10-18

      華為C語言上機試題及答案07-01

      主站蜘蛛池模板: 女性| 无码高清视频在线播放十区| 精品久久精品午夜精品久久| 农村国产毛片一区二区三区女| 岛国中文字幕一区二区| 亚洲大片免费播放地址| 久久久久久AV无码成人| 亚洲无码毛片免费视频在线观看| 酒泉市| 日本人妻高清一区二区三区| 久久国产精品久久国产精品| av免费在线免费在线观看| 国产精品免费av一区二区| 日韩精品夜色二区91久久久| 亚洲青涩在线不卡av| 美女精品黄色淫秽片网站| 国产亚洲美女精品久久久2020| 污污污国产免费网站| 国产三级自拍视频在线| 免费无遮挡毛片中文字幕| 无码视频一区二区三区在线播放 | 麻豆av一区二区三区久久| 国产精品亚洲一区二区v3d| av黄片免费在线观看| 中文字幕日韩人妻高清在线| 欧美zozo另类人禽交| 亚洲国产精品久久久性色av| 国产一区二区三区韩国| 五月激情狠狠开心五月| 依兰县| 极品诱惑一区二区三区| 徐州市| 韩国无码精品人妻一区二| 多伦县| 夫妻一起自拍内射小视频| 伊人色综合九久久天天蜜桃| 久久精品黄色免费热线| 91免费国产| 97久久综合区小说区图片专区| 国产一区二区三区导航| 日本久久久精品视频视频|