您的位置:首页 > 编程语言 > Java开发

2017Java最新编程设计题(含答案)

2017-05-04 12:08 393 查看


1、回文数字判断。

题目描述:

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

要求实现方法:

public String isPalindrome(String strIn);

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

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

false: 不是回文数字;

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

[java] view plain copy

print?

1. package com.iotex;

2.

3. import java.util.Scanner;

4.

5. /**

6. * @author iotex

7. * 2017-5-10下午03:46:56

8. *4、回文数字判断。

9. *题目描述:

10. * 等,这样的数字就称为:

11. *

12. */

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

27.

28.

29.

30.

31. "); 是回文数字!"); }else{ 不是回文数字!"); } } public static boolean isPalindrome(String str){ boolean result = false; for(int i = 0 ;i<str.length()/2-1;i++) { if(str.charAt(i) == str.charAt(str.length()-1-i)) { result = true; }

32. }

33.

34. return result;

35. }

36.

37. }

[java] view plain copy

print?

1. package com.iotex;

2.

3. import java.util.Scanner;

4.

5. /**

6. * @author iotex

7. * 2017-5-10下午03:46:56

8. *4、回文数字判断。

9. *题目描述:

10. * 的数字就称为:

11. * 12. */

13. public class IsPalindrome { 14.

15. ");

16. 17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

27.

28.

29.

30.

31.

32.

33.

34.

35. "); 不是回文数字!"); } boolean result = false; for(int i = 0 ;i<str.length()/2-1;i++) { if(str.charAt(i) == str.charAt(str.length()-1-i)) { result = true; } } return result; }

36.

37. }

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

[java] view plain copy

print?

1. package com.iotex;

2.

3. import java.util.HashSet;

4. import java.util.Set;

5.

6. /**

7. *

8. * @author iotex

9. * 2017-5-10下午04:05:42

10. *5、要求:随机打印50

11. * 4个,要求首字符对齐

12. */

13. public class RandomStr {

14. 15.

16. 17.

18. }

19.

20. 21.

22.

23.

24.

25. } 26. count++;

27. }

28. }

29. /**

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

31. */

32. public static String randomStr(int strLen) {

33. char[] str = new char[strLen];

34. int i = 0;

35. while(i<strLen) {

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

37. if(f == 0) {

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

39. }else if(f == 1) {

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

41. }else {

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

43. }

44. i++;

45. }

46.

47. return new String(str);

48. }

49. }

[java] view plain copy

print?

1. package com.iotex;

2.

3. import java.util.HashSet;

4. import java.util.Set;

5.

6. /**

7. *

8.

9. 04:05:42

10. *54-10

11. * 每行打印4个,要求首

12. */ 13. 14.

15.

16.

17.

18. }

19.

20. int count = 1;

21. for(String i:setStr){

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

23. if(count%4 == 0) {

24. System.out.println();

25. }

26. count++;

27.

28.

29.

30.

31.

32.

33.

34.

35.

36.

37.

38.

39.

40.

41.

42.

43.

44.

45.

46.

47.

48.

49.

} } /** * @param strLen:随机字符串的长度 */ public static String randomStr(int strLen) { char[] str = new char[strLen]; int i = 0; while(i<strLen) { int f = (int)Math.random()*3; if(f == 0) { str[i] = (char)('a' + Math.random()*26); }else if(f == 1) { }else { } i++;
} return new String(str); } }

3、,并输出。提示Map)

实例:

输出: c 3

print?

1.

2.

3. import java.util.HashMap;

4. import java.util.Map;

5.

6. /**

7. *

8. * @author iotex

9. * 2017-5-10下午04:47:45

10. * 6.手动输入一个字符串,仅限小写字母,统计并输出每个字符在字符串中出现的次数,

并输出。

11. * 提示(可以用Map)

12. * 实例:

13. * 输入:aaabbbccc

14. * 输出: a 3

15. * b 3

16. * c 3

17. */

18. public class GetCharCount {

19. public static void main(String[] args) {

20. String str = "aaabbbrcc";

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

22. if (str.matches(reg)) {

23. 24. 25.

26. }

27. }else {

28.

29. }

30. }

31.

32.

33. 34. 35.

36.

37. 38.

39. }

40. 41. } 42. 43.

44. }

45. }

[java] view plain copy

print?

1. package com.iotex;

2.

3. import java.util.HashMap;

4. import java.util.Map;

5.

6. /**

7. *

8. * @author iotex

9. * 2017-5-10下午04:47:45

10. * 6.手动输入一个字符串,仅限小写字母,统计并输出每个字符在字符串中出现的次数,并输出。

11. * 提示(可以用Map)

12. * 实例:

13. * 输入:aaabbbccc

14. * 输出: a 3

15. * b 3

16. * c 3

17. */

18. public class GetCharCount {

19. public static void main(String[] args) {

20. String str = "aaabbbrcc";

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

22. if (str.matches(reg)) {

23.

24.

25. 26. }

27. }else {

28.

29.

30.

31.

32.

33.

34.

35.

36.

37.

38.

39.

40.

41.

42.

43.

44.

45.

"); } } } } return map; } }

Java免费学习资料直播公开课群:175161984
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息