<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            華為Java上機考試題

            時間:2024-07-04 04:09:14 JAVA認證 我要投稿
            • 相關推薦

            華為Java上機考試題

              Java是面向對象語言,Java是一種可以撰寫跨平臺應用程序的面向對象的程序設計語言。下面yjbys小編為大家提供的是Java上機考試題及答案,希望對大家有所幫助!

            華為Java上機考試題

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

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

              [java] view plain?

              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.程序實現目標:求一個整型數組中元素的平均值,并統計其中大于和小于此平均值的元素的個數。

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

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

              [java] view plain?

              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

              [java] view plain?

              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的輸入輸出

              [java] view plain?

              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個,要求首字符對齊

              [java] view plain?

              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

              [java] view plain?

              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}

              [java] view plain?

              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

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

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

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

              [java] view plain?

              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

              [java] view plain?

              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);

              }

              }

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

            2016年華為上機考試題03-08

            華為上機試題匯總01-23

            2017華為JAVA考試試題03-09

            2016年Java認證考試題03-08

            計算機二級java上機試題題庫03-29

            NIIT認證Java考試題庫03-27

            2016年華為認證考試題及答案03-10

            2016最新java考試題庫及答案03-09

            2016年華為認證考試題庫02-26

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看