MR-LI_20200829-李伟江
试卷分析
错题分析:
题目1 :Number类是Long类、Int类、Short类、Byte类的父类。
分析 :包装类没有Int类,应该是Integer类型。
Number类的子类有:Byte类、Short类、Integer类、Long类、Float类、Double类。
题目2:查找1000以内的孪生素数
public class TwinPrime{
public boolean prime( int x ){
for( int i = 2 ; i < x ; i++ ){
if( x % 2 == 0 ){
return false;
}
return true;
}
}
public static void main( String[] args ){
TwinPrime t = new TwinPrime();
for( int i = 2 ; i <= 1000 ; i++ ){
if( t.prime( i ) && t.prime( i + 2 ) ){
System.out.println( i + '\t' + ( i + 2 ) );
}
}
}
}
题目3:求正数数组中的次大数
public class SecondMaxNum2 {
public static void main(String[] args) {
int [] data = new int[]{ 19 , 22 , 98 , 00 , 56 , 77 , 45 , 72 , 0 , -1 };
for( int i = 0 ; i < 2 ; i++ ) { //用冒泡的方式,第二遍循环即可找到次大数
for( int j = 0 ; j < data.length - i - 1 ; j++ ) {
if( data[ j ] > data[ j + 1 ] ) {
int t = data[ j ];
data[ j ] = data[ j + 1 ];
data[ j + 1 ] = t;
}
}
}
System.out.println( data[ data.length - 2 ] );
}
}
题目4:计算字符串的所有碎片的平均长度
public class FragmentAverage{
public static void main( String[] args ){
String s = "aaabbaaac";
char c = s.charAt(0); //将字符串的第0个字符赋值给c
double count = 1;
for( int i = 0 ; i < s.length() ; i++ ){
if( s != s.charAt( i ) ){
c = s.charAt( i );
conut++;
}
}
double d = s.length()/count;
}
}
总结
自身问题:1.概念细节模糊,需要反复看概念。简答题都是靠理解去答的。
2.编程题没有思路,不知道该怎么下手。
近期评论