题目描述:
16. 一个严格递增数列是指每个数都严格比前一个数大的一列数。一个严格递减数列是指每个数都严格比前一个数小的一列数。一个严格单调数列是指严格递增数列或是严格递减数列。例如1, 5, 6, 10 和 9, 8, 7, 1两个数列都是严格单调数列,而 1, 5, 2, 6和 1, 2, 2, 3就不是严格单调数列。给定你一个数列seq,请找到满足严格单调定义的最长连续子数列,并返回其长度
输入:
输入一个整形数组seq。seq含有1到50个元素(其中包括1和50),seq中的每个元素的取值范围都在1和100之间(其中包括1和100
输出:
返回严格单调的最长连续子序列长度
举例:
seq: {1, 7, 7, 8, 3, 6, 7, 2},返回3. 最长的严格单调数列是3,6,7.而子数列1,3,6,7是不符合要求的,因为1和3并不相连,此外1,7,7,8也是满足条件的,因为它不是严格递增的
/******************************************
* 在这里输入代码
* 你不需要写main函数,系统将自动调用longestMonotoneSequence函数
******************************************/
public static intlongestMonotoneSequence(int[] seq) {
int res=1;
int current=1;
for(int i=1;i<seq.length;i++){
if(seq[i]>seq[i-1]){
current++;
}
else{
if(current>res){
//index=i-current;
res=current;
}
current=1;
}
}
return res;
}
题目描述:
15. 给定你五个正整数,它们最小众倍数是指能够被其中至少三个数整除的最小正整数。给定你各不相同的整型a, b, c, d以及e。请返回它们的最小众倍数。
输入:
输入五个正整数a,b,c,d,e。a, b, c, d以及e中每个的取值范围都在1和100之间(其中包括1和100)。a, b, c, d以及e各不相同
输出:
返回它们的最小众倍数
举例:
a = 1 b = 2 c = 3 d = 4 e = 5, 返回4。4能够被1,2以及4整除,满足五个数中至少能被其中三个整除的定义
/******************************************
* 在这里输入代码
* 你不需要写main函数,系统将自动调用leastMajorityMultiple函数
******************************************/
public static int leastMajorityMultiple(inta, int b, int c, int d, int e){
int i=1;
int count =0;
while (i>0)
{
if(i%a == 0) count++;
if(i%b == 0) count++;
if(i%c == 0) count++;
if(i%d == 0) count++;
if(i%e == 0) count++;
if (count >= 3)
{
System.out.println("find");
break;
}
count = 0;
i++;
}
return i;
}
编程题
题目描述:
14. 给定一个rSquare,表示一个圆的半径的平方。某圆的圆心在坐标系原点,需要计算返回处在该圆圆周上的格点(横纵坐标均为整数的点)数量。
输入:
输入一个整数rSquare。rSquare的取值范围在1到2,000,000,000之间(其中包括1和2,000,000,000)
输出:
返回圆上的格点数量
举例:
rSquare = 1,返回4. 圆心在原点、半径为1的圆通过4个格点:(1,0)、(0,1)、(-1,0)和(0,-1)
/******************************************
* 在这里输入代码
* 你不需要写main函数,系统将自动调用countPoints函数
******************************************/
public static int countPoints(int rSquare){
int counter=0;
for(int i = 1 ; i < 44722 ; i++){
for(int j = i ; j < 44722 ; j++){
int i2 = i * i ;
int j2 = j * j ;
int temp=i2+j2;
if(temp==rSquare)counter++;
}
}
return counter;
}
1. 一般交换机会处于那一层?
物理层
数据链路层
网络层
2. 下面程序输出的结果为:
public class KaoTi {
static int cnt=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
fib(9);
System.out.println(cnt);
}
static int fib(int n)
{
cnt++;
if(n==0)
return 1;
else if(n==1)
return 2;
else
return fib(n-1)+fib(n-2);
}
}
109
3. int n=1,则 ++(n++)的值是?
2
4. 下面程序输出的结果为:
public class KaoTi {
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t = new Thread() {
public void run() {
nowCoder();
}
};
t.run();
System.out.print("hello");
}
static synchronized void nowCoder() {
System.out.print("nowcoder");
}
}
nowcoderhello
5. 字符 String str="\\\12345678\t";的长度为
8
6. 以下代码的输出结果是:
puKaotilic class Kaoti
{
puKaotilic static Kaoti t1 = newKaoti();
puKaotilic static Kaoti t2 = newKaoti();
{
System.out.println("我是构造块");
}
static
{
System.out.println("我是静态块");
}
puKaotilic static void main(String[]args)
{
Kaoti t = new Kaoti();
}
}
我是构造块我是构造块我是静态块我是构造块
7. 在java里面创建对象时必须先声明对象,为对象分配内存空间,然后才能使用对象。
错
8. 在java里面Math.abs返回值
不可能是负数
9. 下面字符串最终的结果为()
String str="Hello World";
str=str.substring(3,6);
lo W
10. 采用哈希表组织100万条记录,以支持某字段的快速查找,理论上可以在常数时间内找到特定记录。
false
11. 下面代码段输出的结果为:
public class KaoTi{
public static void main(String[]args){
short s1 = 128; s1 += 1;
System.out.println(s1);
}
}
129
12. 下面程序输出的结果可能为:
import java.util.*;
public class Test {
public static void main(String[] args) {
HashMap map = new HashMap < Integer,Integer > ();
changeHashMap(map);
for (Iterator it =map.keySet().iterator(); it.hasNext();) {
Object key = it.next();
System.out.println(key + "="+ map.get(key));
}
}
static void changeHashMap(HashMap map) {
map = new HashMap < Integer, String> ();
map.put(6, "apple");
map.put(3, "banana");
map.put(2, "pear");
map.put(null, null);
map.put(null, null);
}
}
无输出内容
13. 下面程序运行后,说法正确的是:
import java.io.*;
public class KaoTi {
public static void main(String[] args) {
// TODO Auto-generated method stub
Strings="1234567890abcdefghijklmnopq";
byte[] b=s.getBytes();
try{
File f=newFile("B.txt");
FileOutputStream outputStream=newFileOutputStream(f);
outputStream.write(b,10,10);
outputStream.write(b,0,5);
}catch (IOException e){
System.out.println(e.getMessage());
}
}
}
程序编译正常,但屏幕没有任何输出
17. 牛客有3名保安人员,平均每人一周工作42小时,每人每周最少工作35小时,问一人每周最多工作时间?
56
18. 下面说法正确的是:
循环队列中元素的个数是有队头指针和队尾指针共同决定
19. 一颗二叉搜索树共有n个节点,在这颗二叉树中查找到目标的最差时间复杂度为
O(n
20. 某棵完全二叉树上有333个节点,则该二叉树的叶子节点数为
166
21. 在java中,下列声明数组错误的是:
int[][1] arr
22. 在java的整形数据类型中,下列选项那个在占用的内存空间最少
Byte
23. JDK提供的用于并发编程的同步器有 CyclicBarrier、CountDownLatch、Counter和Semaphore。
错