公司支付的网站建设如何入账,百度怎么收录自己的网站,镇江市住房城乡建设局网站,天津软件优化公司排名前十目录
1. 求正数数组的最小不可组成和
2. 有假币
3. 继承时先调用父类的构造方法;类中的成员变量的初始化操作都在构造方法时进行
4. 学会并理解装箱拆箱,注意new出来的也可以拆!!
5. getDeclaredMethods()是标识类或接口的声明成员(这个表示public private 包访问权限 pro…目录
1. 求正数数组的最小不可组成和
2. 有假币
3. 继承时先调用父类的构造方法;类中的成员变量的初始化操作都在构造方法时进行
4. 学会并理解装箱拆箱,注意new出来的也可以拆!!
5. getDeclaredMethods()是标识类或接口的声明成员(这个表示public private 包访问权限 protected)的集合,不包括继承的成员
6. 最难的问题
7. 因子个数 1. 求正数数组的最小不可组成和
题目链接求正数数组的最小不可组成和_百度笔试题_牛客网 (nowcoder.com)
题目要求 题目分析 上代码
import java.util.*;
public class Solution {/*** 正数数组中的最小不可组成和* 输入正数数组arr* 返回正数数组中的最小不可组成和*/public int getFirstUnFormedNum(int[] arr) {//1.设置min和maxint min Integer.MAX_VALUE;int max 0;for (int i : arr) {min Math.min(min,i);max i;}boolean[] result new boolean[max1];//2.设置result初始状态result[0] true;//3.两层循环遍历arr和resultfor (int i : arr) {for (int j max; j i; j--) {result[j] result[j-i] || result[j];}}//4.遍历result数组,找出第一个不为true的for (int i min; i result.length; i) {if(!result[i]) {return i;}}//result都为true那就输出max1return max1;}
} 2. 有假币
题目链接有假币__牛客网 (nowcoder.com)
题目要求 题目分析 上代码
import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner scan new Scanner(System.in);while(scan.hasNext()) {int n scan.nextInt();if(n 0) break;int count 0;while(n 2) {n (int)Math.ceil((double)n/3);count;}System.out.println(count);}}
} 3. 继承时先调用父类的构造方法;类中的成员变量的初始化操作都在构造方法时进行
以下程序执行的结果是: (C) A. ZYXX B. ZYXY C. YXYZ D. XYZX 首先明确,继承时先调用父类的构造方法 类中的成员变量的初始化操作都在构造方法时进行 所以当main中new了Z后,先调用父类的构造方法, 而在父类构造方法中又实例化了Y,那就导致先执行Y的构造方法 第一个打印Y 下来X才执行自己的构造方法 第二个打印X 当父类构造执行完后,此时才到执行子类自己的了 Z自己先new了个Y,导致执行Y的构造方法, 第三个打印Y 然后Z才执行自己的构造方法 第四个打印Y 4. 学会并理解装箱拆箱,注意new出来的也可以拆!!
有如下4条语句: ( C )
Integer i01 59;
int i02 59;
Integer i03 Integer.valueOf(59);
Integer i04 new Integer(59);
以下输出结果为false的是:
A. System.out.println(i01 i02);
B. System.out.println(i01 i03);
C. System.out.println(i03 i04);
D. System.out.println(i02 i04); Integer i01 59; 自动装箱 int i02 59; Integer i03 Integer.valueOf(59); 装箱 Integer i04 new Integer(59); 在堆上new了个对象 A. 选项是i01 i02 就是将i01自动拆箱,还原为整型 true B. 是i01 i03 都是Integer 所以为true C. 是i03 i04 因为i04是new出来的,就有新的地址,所以i03 和 i04 不等 D. 是i02 i04 因为i04发生自动拆箱,i04就还原为int了,所以为true 选C 5. getDeclaredMethods()是标识类或接口的声明成员(这个表示public private 包访问权限 protected)的集合,不包括继承的成员
考虑下面这个简单的例子,让我们看看reflection是如何工作的 其中c.gerDeclaredMethods的作用是:
A. 取得类的公有方法对象
B. 取得类的所有公有方法名称
C. 取得类的所有方法对象
D. 以上选项都不正确 通过查看源码,可以看到 getMethods()是标识类或接口的所有公共成员的集合,包括继承的成员 而getDeclaredMethods()是标识类或接口的声明成员(这个表示public private 包访问权限 protected)的集合,不包括继承的成员 所以选D,都不正确 6. 最难的问题
题目链接最难的问题__牛客网 (nowcoder.com)
题目要求 题目分析 上代码
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scan new Scanner(System.in);while(scan.hasNext()) {String str scan.nextLine();StringBuilder sb new StringBuilder();for (int i 0; i str.length(); i) {char c str.charAt(i);if(c ) {sb.append( );}else {sb.append((char)(c E ? c-5 : c21));}}System.out.println(sb);}}
}7. 因子个数
题目链接因子个数__牛客网 (nowcoder.com)
题目要求 题目分析 上代码
// write your code here
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner scan new Scanner(System.in);while(scan.hasNext()) {int n scan.nextInt();int count 0;for (int i 2; i*i n; i) {if(n%i 0) {while(n%i 0) {n / i;}count;}}//走到这里有两种情况,n1 n ! 1if(n ! 1) count;System.out.println(count);}}
}