java入职笔试题(2)

2020-02-21 12:39

18. 编程题:将一个ISO-8859-1编码的字符串转成UTF-8编码字符串 Public String translate (String str) {

String tempStr = \ try {

tempStr = new String(str.getBytes(\ tempStr = tempStr.trim(); }

catch (Exception e) {

System.err.println(e.getMessage()); }

return tempStr; }

19. 类Test中有invokeMethod方法,请根据invokeMethod补全toClassArgs方法(反射,

method动态调用)

public static Object invokeMethod(Object instance,String methodName,Object...args) {

Class[] c =null; if(args!=null){ }

Method theMethod; try {

theMethod = instance.getClass().getMethod(methodName,c); return theMethod.invoke(instance, args); c = Test.toClassArgs(args);

}

} catch (Exception e) { }

return null;

// TODO Auto-generated catch block e.printStackTrace();

public static Class[] toClassArgs(Object...args){

}

20. Javascript中,imgBtn为一个页面dom对象,当调用init方法时,会对imgBtn添加一个

onclick事件,点击imgBtn时alert出init的入口参数msg(闭包)

function init(msg){

var imgBtn = document.getElementById(“imgBtn”); imgBtn.onclick = function(){ alert(msg); } }

21. 判断101-200之间有多少个素数,并输出所有素数 public class Test {

public static void main(String[] args) { int count = 0;

for(int i=101; i<200; i+=2) { boolean b = false;

for(int j=2; j<=Math.sqrt(i); j++) {

if(i % j == 0) { b = false; break; } else { b = true; } }

if(b == true) {count ++;System.out.println(i );} }

System.out.println( \素数个数是: \} }

22. 编程题: 写出一个Singleton的类

package com.md.test;

public class Sigleton {

public static Sigleton getInstance() { }

public static Sigleton instance = null; private Sigleton() {

}

if (instance == null) { }

return instance;

return new Sigleton();

}

23. 编程题:以1,2,3,4,5……的格式,返回从1到1000的字符串,供多用户频繁调用(结

尾无逗号)

package com.md.test;

public class Test { }

public static void main(String[] args) { }

StringBuffer sb = new StringBuffer(); for(int i = 0 ;i<=1000;i++){ }

System.out.println(sb);

sb.append(String.valueOf(i)).append(\);

24.

25. 将一个6位以下的整数输出为10位长度的字符串,补充前置零。

package com.md.test;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

String str = \;

Scanner sc = new Scanner(System.in);

System.out.print(\请输入一个不多于5位的正整数:\); long a = sc.nextLong(); String ss = Long.toString(a); char[] ch = ss.toCharArray();

int j = ch.length;

System.out.println(a + \是一个\ + j + \位数。\); System.out.print(\输出的结果是:\); for (int i = 0; i < ch.length; i++) { if (j == 0) { System.out.print(\);

}

if (j == 1) { System.out.print(\+ch[i]); }

if(j==2){ System.out.print(\+ch[i]); }

if(j==3){ System.out.print(\+ch[i]); }

if(j==4){ System.out.print(\+ch[i]); }

if(j==5){ System.out.print(\+ch[i]); }

if(j==6){ System.out.print(ch[i]);

}

}

}

}

26. Student(S#,Sname,Sage,Ssex)

学生

Course(C#,Cname,T#) 课程SC(S#,C#,score)

Teacher(T#,Tname) 教师表

表表表

S# C# T#为编号 写出sql

查询“001”课程比“002”课程成绩高的所有学生的学号

Select s# from sc where score > (Select score from sc where cname=’001’) and cname=’002’

查询平均成绩大于60分的同学的学号和平均成绩;

Select s#,avg(score) from sc group by s# having avg(score)>’60’ 查询学过“001”并且也学过编号“002”课程的同学的学号、姓名

Select s#,sname from student t1, sc t2 where s# =( select s# from sc where c#=’001’) and s#=’002’


java入职笔试题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:11月11日光棍节策划[1]

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: