论坛首页 招聘求职版 求职经验

经典面试题````大家来看看怎么做

浏览 4046 次
精华帖 (0) :: 良好帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-05-01
第一题,字符串数组版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String[] taxis = { "D", "C", "B", "A" };
Arrays.sort(taxis);
for (String string : taxis) {
System.out.println(string);
}
}
}
单字符串版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String taxis = "dcba";
char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);
Arrays.sort(chars);
for (char c : chars) {
System.out.println(c);
}
}
}
   
0 请登录后投票
时间:2008-05-01
第二题
import java.util.Map;
import java.util.TreeMap;
public class Test2 {
public static void main(String[] args) {
String string = "asdffdghsafagf测试";
Map<Character, Integer> map = new TreeMap<Character, Integer>();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (map.containsKey(c)) {
map.put(c, map.get(c) + 1);
} else {
map.put(c, 1);
}
}
for (Character c : map.keySet()) {
System.out.print(c + "(" + map.get(c) + ")");
}
}
}
运行结果:
a(3)d(2)f(4)g(2)h(1)s(2)测(1)试(1)
   
0 请登录后投票
时间:2008-05-02
totong 写道
第一题,字符串数组版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String[] taxis = { "D", "C", "B", "A" };
Arrays.sort(taxis);
for (String string : taxis) {
System.out.println(string);
}
}
}
单字符串版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String taxis = "dcba";
char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);
Arrays.sort(chars);
for (char c : chars) {
System.out.println(c);
}
}
}


受教了```使用Arrays类来操作数组排序

char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);

这段代码可以改成这样
char tax[]=taxis.toCharArray();
   
0 请登录后投票
时间:2008-05-03
6246850 写道
totong 写道
第一题,字符串数组版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String[] taxis = { "D", "C", "B", "A" };
Arrays.sort(taxis);
for (String string : taxis) {
System.out.println(string);
}
}
}
单字符串版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String taxis = "dcba";
char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);
Arrays.sort(chars);
for (char c : chars) {
System.out.println(c);
}
}
}


受教了```使用Arrays类来操作数组排序

char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);

这段代码可以改成这样
char tax[]=taxis.toCharArray();

写法简单了一些,不错
看到这样的要求,我习惯上就去找get开头的方法了,没注意到还有toCharArray,呵呵
   
0 请登录后投票
时间:2008-05-05
晕,深圳太极的面试题
   
0 请登录后投票
时间:2008-05-05
yyawyy 写道
晕,深圳太极的面试题

是啊
你知道深圳太极吗?
   
0 请登录后投票
时间:2008-05-05
totong 写道
第一题,字符串数组版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String[] taxis = { "D", "C", "B", "A" };
Arrays.sort(taxis);
for (String string : taxis) {
System.out.println(string);
}
}
}
单字符串版本
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
String taxis = "dcba";
char[] chars=new char[taxis.length()];
taxis.getChars(0, taxis.length(), chars, 0);
Arrays.sort(chars);
for (char c : chars) {
System.out.println(c);
}
}
}




支持,是我也用这种办法,没有必要自己写那些算法,当然自己写可以练练水平,单开发速度而言就不言而俞了.况且现在内存性能也不会影响到哪里
   
0 请登录后投票
时间:2008-05-15
只用了冒泡排序,本人同样可以用快速排序,归并排序...
static void sort(String[] strArray, boolean caseIngore) {
String temp;
int length = strArray.length;
boolean isGreater;
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - i - 1; j++) {
if (caseIngore) {
isGreater = strArray[j].compareToIgnoreCase(strArray[j + 1]) > 0;
} else {
isGreater = strArray[j].compareTo(strArray[j + 1]) > 0;
}
if (isGreater) {
temp = strArray[j + 1];
strArray[j + 1] = strArray[j];
strArray[j] = temp;
}
}
}
}
   
0 请登录后投票
时间:2008-05-16
前面好像都很简单。后面那些原理可难可易,看你怎么忽悠了
   
0 请登录后投票
时间:2008-05-16
小白·菜 写道
前面好像都很简单。后面那些原理可难可易,看你怎么忽悠了

恩```
现在已经搞清楚了
   
0 请登录后投票
论坛首页 招聘求职版 求职经验

跳转论坛:
JavaEye推荐