三个常考面试题
来源:互联网 发布:涂鸦 知乎 编辑:程序博客网 时间:2024/06/05 11:26
问题如下:
1. 求从10到100中能被3或5整除的数的和
2. 将一个字符串逆序,不要使用反转函数
3. 反转一个栈
1. 求从10到100中能被3或5整除的数的和
1
2
3
int
sum =
0
;
for
(
int
i =
10
; i <=
100
; i++)
if
( i %
3
==
0
|| i %
5
==
0
) sum += i;
System.out.println(sum);
2. 将一个字符串逆序,不要使用反转函数
1
2
3
4
String message =
"he saw a racecar"
;
StringBuilder rev =
new
StringBuilder();
for
(
int
i = message.length()-
1
; i >=
0
; i--) rev.append(message.charAt(i));
System.out.println(rev.toString());
3. 反转一个栈
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import
java.util.*;
public
class
MyProgram
extends
com.ktbyte.submit.Coder {
public
static
void
main(String[] args) {
Stack items =
new
Stack();
items.push(
"he"
);
//he is at the bottom of the stack
items.push(
"saw"
);
items.push(
"a"
);
items.push(
"racecar"
);
reverseStack(items);
//now he is at the top
//print in order pushed:
while
(items.size()>
0
) System.out.println(items.pop());
}
public
static
void
reverseStack(Stack stack) {
Queue rev =
new
LinkedList();
while
(stack.size()>
0
) rev.offer(stack.pop());
while
(rev.size()>
0
) stack.push(rev.poll());
}
}
0 0
- 三个常考面试题
- 微软面试题--三个灯泡--三个开关
- 微软面试题--三个灯泡--三个开关
- 微软面试题--三个灯泡--三个开关
- 多线程编程之三个面试题
- 《剑指offer》的又三个面试题
- 关于线程的面试题:利用三个线程,循环打印ABC三个数十遍
- [各种面试题] 找出三个只出现一次的数
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 不少程序员都会碰到的三个面试题
- 约数个数定理
- 二叉搜索树的后序遍历序列
- 数据挖掘方法案例介绍
- HDU 2521 反素数【打表】
- POJ 1183---反正切函数的应用【数学问题】
- 三个常考面试题
- 杭电ACM2030汉字统计-----20140729
- hdoj.2051 Bitset 20140729
- 入手Cubieboard2之制作最小Linux系统
- Mysql Master-Slave 简单介绍
- strip()、 lstrip()、 rstrip()使用方法
- FPGA学习启动计划
- Spark programming guide
- HDU 1874 SPFA