2017年华为Java机试题锦集

文书君 人气:2.38W

Java对程序提供了安全管理器,防止程序的非法访问。下面是小编收集的华为Java机试题,希望大家认真阅读!

2017年华为Java机试题锦集

1.程序实现目标: 输入一个字符串,将其各个字符对应的ASCII值加5后,输出结果。

程序要求:该字符串只包含小写字母,若其值加5后的字符值大于'z',将其转换成从a开始的字符。

package yond;

/**

* @author xcbeyond

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

* 1.程序实现目标: 输入一个字符串,将其各个字符对应的ASCII值加5后,输出结果。

* 程序要求:该字符串只包含小写字母,若其值加5后的字符值大于'z',将其转换成从a开始的字符。

*/

public class StringParseASCII {

public static void main(String[] args) {

t(stringParseASCII("abx"));

}

public static String stringParseASCII(String str){

StringBuffer result = new StringBuffer();

char tmp;

for(int i = 0;i

tmp = (char)(At(i)+5);

if(tmp > 'z') {

nd('a');

}else {

nd(tmp);

}

}

return ring();

}

}

2.程序实现目标:求一个整型数组中元素的平均值,并统计其中大于和小于此平均值的元素的个数。

程序要求:输入:整型数组中的元素个数及各个元素。

输出:整型数组中元素的平均值,大于和小于此平均值的元素的个数。

package yond;

import ys;

/**

*

* @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};

tln(ring(array)+"的平均值:"+avg(array)+"n" +

"大于和小于平均值元素的个数分别为:"+ring(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/th;

return average;

}

}

3、手动输入一个存储整数的数组,要求输出数组里面的2个最大值。

实例:

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

输出:84,9

package yond;

import ys;

/**

* @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};

tln("数组"+ring(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;

}

}

}

tln(array[0]+"、"+array[1]);

}

}

4、回文数字判断。

题目描述:

有这样一类数字,他们顺着看和倒着看是相同的数,例如:121,656,2332等,这样的数字就称为:回文数字。编写一个函数,判断某数字是否是回文数字。

要求实现方法:

public String isPalindrome(String strIn);

【输入】strIn: 整数,以字符串表示;

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

false: 不是回文数字;

【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出

package yond;

import ner;

/**

* @author xcbeyond

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

*4、回文数字判断。

*题目描述:

* 有这样一类数字,他们顺着看和倒着看是相同的数,例如:121,656,2332等,这样的数字就称为:

* 回文数字。编写一个函数,判断某数字是否是回文数字。

*/

public class IsPalindrome {

public static void main(String[] args) {

t("请输入一个回文数字:");

Scanner console = new Scanner();

String numStr = Line();

if(isPalindrome(numStr)) {

tln(numStr+"是回文数字!");

}else{

tln(numStr+"不是回文数字!");

}

}

public static boolean isPalindrome(String str){

boolean result = false;

for(int i = 0 ;i

if(At(i) == At(th()-1-i)) {

result = true;

}

}

return result;

}

}

5、要求:随机打印50个随机(4-10长度)的字符串,要求字符串包含的范围是所有的英文字母包含大小写和数字,按照编码顺序排序,每行打印4个,要求首字符对齐

package yond;

import Set;

import ;

/**

*

* @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++) {

(randomStr(5));

}

int count = 1;

for(String i:setStr){

t(i+" ");

if(count%4 == 0) {

tln();

}

count++;

}

}

/**

* @param strLen:随机字符串的长度

*/

public static String randomStr(int strLen) {

char[] str = new char[strLen];

int i = 0;

while(i

int f = (int)om()*3;

if(f == 0) {

str[i] = (char)('a' + om()*26);

}else if(f == 1) {

str[i] = (char)('A' + om()*26);

}else {

str[i] = (char)('0' + om()*10);

}

i++;

}

return new String(str);

}

}

6.手动输入一个字符串,仅限小写字母,统计并输出每个字符在字符串中出现的次数,并输出。提示(可以用Map)

实例:

输入:aaabbbccc

输出:a 3

b 3

c 3

package yond;

import Map;

import ;

/**

*

* @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 (hes(reg)) {

Map map = getCharCount(str);

for (y e : ySet()) {

tln(ey() + ": " + alue());

}

}else {

tln("输入的字符不合法,不是小写字母");

}

}

public static Map getCharCount(String str) {

Map map = new HashMap();

char[] arr = arArray();

for(int i = 0;i

if(!ainsKey(arr[i])) {

(arr[i], new Integer(1));

}else {

(arr[i],(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();

woBigNumber("123456789","987654321")

}

}

8、比较二维数组列最小值,组成一个新数组返回。(实现核心算法,不需要使用IO)

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

输出:intArrs ={1,3}

package yond;

import ys;

/**

* @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}};

tln(ring(getColMin(arr)));

}

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

int[] minArr = new int[th];

for(int i = 0;i

int[] tmp = arr[i];

(tmp);

minArr[i] = tmp[0];

}

return minArr;

}

}

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

输出: tiger

功能描述:键盘输入一句话

输出一句话中最常的单词,如果最长的出现多次,返回第一个。

这句话只包含数字字母和标点。

package yond;

import yList;

import ner;

/**

*

* @author xcbeyond

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

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

* 输出: tiger

* 功能描述:键盘输入一句话

* 输出一句话中最常的单词,如果最长的出现多次,返回第一个。

* 这句话只包含数字字母和标点。

*/

public class GetLongString {

public static void main(String[] args) {

tln("请输入一句话:");

Scanner console = new Scanner();

String str = Line();

tln("最长的单词为:"+getLongString(str));

}

public static String getLongString(String str) {

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

int sum = 0;

ArrayList result = new ArrayList();

for(int i = 0;i

if(sum

sum = wordStr[i]th();

(wordStr[i]);

}

}

return (()-1);

}

}

10. 功能描述:将字符串中的字母全部替换成字母的下一个字母,

要是最后一位是z或Z则替换为a或A。

输入:aBxyZ

输出:bCyzA

package yond;

/**

*

* @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";

tln(nextString(str));

}

public static String nextString(String str) {

String result = "";

char[] arr = arArray();

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 eOf(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 yond;

import yList;

import ections;

import arator;

import Map;

import ;

import ;

import y;

/**

*

* @author xcbeyond

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

*/

public class DeleteLittle {

public static void main(String[] args) {

String str = "asdasdas";

tln(deleteLittle(str));

}

public static String deleteLittle(String str) {

Map map = new HashMap();

char[] ch = arArray();

for(int i = 0;i

if(!ainsKey(ch[i])){

(ch[i], 1);

}else {

(ch[i], (ch[i])+1);

}

}

List> list = new ArrayList>(ySet());

(list, new Comparator>(){

@Override

public int compare(Entry o1,

Entry o2) {

return alue()areTo(alue());

}

});

String[] s = t((0)ey()ring());

StringBuffer sb = new StringBuffer();

for(int i = 0;i

nd(s[i]);

}

return ring();

}

}

14. 功能描述:找出一个int[]中满足 2^n的数字,然后组成的新的数组

输入:{4,3,8}

输出:{4,8}

package yond;

import yList;

import ys;

import ;

/**

*

* @author xcbeyond

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

*/

public class NextString {

public static void main(String[] args) {

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

tln(ring(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) {

(arr[i]);

}

}

int[] resultArr = new int[()];

for(int i = 0;i<();i++) p="">

resultArr[i] = (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 yond;

import ys;

import Map;

import ;

/**

* @author xcbeyond

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

*/

public class IntParseBinary {

public static void main(String[] args) {

int data = 6;

tln(ring(getNumber(data)));

}

public static int[] getNumber(int data) {

char[] binaryStr = naryString(data)arArray();

Map map = new HashMap();

for(int i = 0;i

if(!ainsKey(binaryStr[i])) {

(binaryStr[i], 1);

}else{

(binaryStr[i], (binaryStr[i])+1);

}

}

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

}

}

17. 功能描述:对一个二进制数的每位进行0和1反转,求翻转后的二进制所对应的十进制

输入:1010

输出:5

package yond;

/**

*

* @author xcbeyond

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

*/

public class BitReverse {

public static void main(String[] args) {

String data = "1010";

tln(getNumber(data));

}

public static String getNumber(String data){

char[] dataStr = arArray();

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 = eOf(str, 2)ring();

return res;

}

}

18. 功能描述:判断一个字符串中的"( )"是否配对

输入:if(ls(a))

输出:true

package yond;

/**

* @author xcbeyond

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

*/

public class IsMatch {

public static void main(String[] args) {

String str = "if(ls(a))";

tln(isMatch(str));

}

public static boolean isMatch(String str){

boolean isMatch = false;

char[] ch = arArray();

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

import ys;

/**

* @author xcbeyond

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

*/

public class Demo20 {

public static void main(String[] args) {

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

tln(ring(getChildren(data,2)));

}

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

String[] resData = new String[th];

for(int i = 0;i

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

}

resData[th-1] = data[0];

return resData;

}

}

21. 程序实现目标: 输入一个字符,将字符转换为小写,将其对应的ASCII值加5后,输出结果。

程序要求:若其值加5后的字符值大于'z',将其转换成从a开始的'字符。

输入:‘A’

输出:‘f’

package yond;

/**

*

* @author xcbeyond

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

*/

public class Demo21 {

public static void main(String[] args) {

tln(parseChar('X'));

}

public static char parseChar(char ch) {

char resCh = 'a';

resCh = (char)(werCase(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 yond;

import om;

/**

*

* @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

t(arr2[i][j]+" ");

}

tln();

}

}

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

int[][] resArr = new int[th][];

for(int i = 0 ;i

resArr[th-1-i] = arr[i];

}

Random r = new Random();

for(int i = 0 ;i

for(int j = 0;j

int p = Int(resArr[i]th);

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

/**

* @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

t(arr2[i][j]+" ");

}

tln();

}

}

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

int[][] resArr = new int[arr[0]th][th];

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

/**

*

* @author xcbeyond

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

*/

public class Demo27 {

public static void main(String[] args) {

String str = "h3a2p0p1y";

tln(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((At(i)+"")hes(numRegex)) {

numStr += At(i);

}else if((At(i)+"")hes(strRegex)) {

str += At(i);

}

}

return str+numStr;

}

}

28. 输入一个身份证号码(15位和18位)和一个年份,计算现在的年龄(忽略非法参数)

eg:610618199001020065 2011

输出:21

package yond;

/**

*

* @author xcbeyond

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

*/

public class Demo28 {

public static void main(String[] args) {

String id = "610618199001020065";

tln(countAge(id,2011));

}

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

String birthDate = "";

if(th() == 15) {

birthDate = tring(3, 7);

}else if(th() == 18) {

birthDate = tring(6, 10);

}

int age = 0;

age = date - eInt(birthDate);

return age;

}

}

29. 输入一个字符串,如果是小写则转换成相应的大写字母的后五位,如果是VWXYZ则转换成abcde,其他的都不变,例如:“aDsR154+-/.”则应该输出为“FDXR154+-/.”

package yond;

/**

*

* @author xcbeyond

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

*/

public class Demo29 {

public static void main(String[] args) {

String str = "aDsR154+-/.";

tln(parseStr(str));

}

public static String parseStr(String str) {

StringBuffer sb = new StringBuffer();

char tmp;

for(int i = 0;i

if(At(i)>='a' && At(i)<='z') {

tmp =(char)(perCase(At(i))+5);

if(tmp > 'Z') {

tmp = (char)(tmp - 26);

}

nd(tmp);

}else {

nd(At(i));

}

}

return ring();

}

}

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

/**

*

* @author xcbeyond

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

*/

public class Demo30 {

public static void main(String[] args) {

char ch = 'A';

tln(upperToLower(ch));

}

public static char upperToLower(char upperCase) {

char resCh = 'a';

resCh = (char)(werCase(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 yond;

/**

*

* @author xcbeyond

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

*/

public class Demo33 {

public static void main(String[] args) {

String str = "I am a boy";

tln(reverse(str));

}

public static String reverse(String sentence) {

String regex = "[ *]";

String[] ch = t(regex);

StringBuffer sb = new StringBuffer();

for(int i=th-1;i>=0;i--) {

nd(ch[i]+" ");

}

return ring();

}

}

34. 题目背景

写出一个程序,接受一个浮点数值,输出该数值的近似整数值。如果小数点后数值大于等于5,向上取整;小于5,则向下取整

接口

int round(double d)

举例

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

4.4 四舍五入的结果是4

package yond;

/**

*

* @author xcbeyond

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

*/

public class Demo34 {

public static void main(String[] args) {

double d = 3.65;

tln(round(d));

}

public static int round(double d) {

String str = ring(d);

String subStr = tring(xOf('.')+1, xOf('.')+2);

int a = eInt(subStr);

int res = 0;

if(a <5) {

res = (int)r(d);

}else {

res = (int)(d);

}

return res;

}

}

35.数列求和

编写程序,输入一个正整数n,求下列算式的值。要求定义和调用函数fact(k)计算k的阶乘,函数返回值的类型是double。

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

输出保留5位小数。

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

Input 5

Output 1.71667

package yond;

public class Demo35 {

public static void main(String[] args) {

tln(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 yond;

/**

*

* @author xcbeyond

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

*/

public class Demo36 {

public static void main(String[] args) {

int num = 123;

tln(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 yond;

/**

*

* @author xcbeyond

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

*/

public class Demo37 {

public static void main(String[] args) {

int num = -12310;

tln(getConvertInt(num));

}

public static int getConvertInt(int num) {

String str = eOf(num);

StringBuffer sb = new StringBuffer();

boolean flg = true;

if(At(0) == '-') {

flg = false;

nd(At(0));

}

if(At(th()-1) != '0') {

nd(At(th()-1));

}

for(int i = th()-2;i>0;i--) {

nd(At(i));

}

if(flg) {

nd(At(0));

}

return eInt(ring());

}

}

TAG标签:华为 锦集 试题 Java