Java 笔试题 大家来讨教交流下(中软公司部分笔试)
答案:3 悬赏:80 手机版
解决时间 2021-04-12 18:55
- 提问者网友:蓝莓格格巫
- 2021-04-12 08:08
Java 笔试题 大家来讨教交流下(中软公司部分笔试)
最佳答案
- 五星知识达人网友:渡鹤影
- 2021-04-12 09:28
1.
------------------------------
public class Test1{
private Test1 test=new Test();
private String addr;
private int port;
private String username;
private String pwd;
private Test1(){
File file=new File("context.properties");
Scanner s=new Scanner(file);
while(s.hasNextLine()){
String temp=s.nextLine().trim();
if(temp.indexOf("=")>0){
String left=temp.substring(0,temp.indexOf("=")).trim();
String right=temp.substring(temp.indexOf("=")+1,temp.length()).trim();
if(left.equals("addr")) addr=right;
else if(left.equals("port")) port=Integer.parstInt(right);
else if(left.equals("username")) username=right;
else if(left.equals("pwd")) pwd=right;
}
}
}
public Test1 getSingleton(){
return test;
}
}
-------------------------
2:
class public Test2{
static private int i=0;
static public void add(){
i++;
}
static public void dec(){
i--;
}
}
public class A extends Thread{
public A(){
}
public void run(){
Test2.add();
}
}
public class B extends Thread{
public B(){
}
public void run(){
Test2.add();
}
}
public class C extends Thread{
public C(){
}
public void run(){
Test2.dec();
}
}
public class D extends Thread{
public D(){
}
public void run(){
Test2.dec();
}
}
-------------------
3.
public String substringByLast(String line,int last){
return line.substring(0,last);
}
--------------------
4.
student.js
var name;
var age;
var number;
function student(nameX,ageX,numberX){
name=nameX;
age=ageX;
number=numberX;
}
function say(){
alert('My name is'+name+',I am '+age+',My number is '+number;
}
5.
-------------------------
ls 显示目录下所有文件
cd 定位目录
mkdir rmdir 新建、删除目录
cp 复制文件
cat 显示txt文本文件
grep find 查找文件中字符串
6.
------------------------
SELECt avg(成绩) FROM 选课
WHERe 学号 IN(SELECt 学号 FROM 学生 WHERe 性别='男')
AND 课程号 IN(SELECt 课程号 FROM 课程 WHERe 课程名='语文')
SELECt max(成绩) FROM 选课
WHERe 学号 IN(SELECt 学号 FROM 学生 WHERe 性别='男')
AND 课程号 IN(SELECt 课程号 FROM 课程 WHERe 课程名='语文')
其他只需要修改
------------------------------
public class Test1{
private Test1 test=new Test();
private String addr;
private int port;
private String username;
private String pwd;
private Test1(){
File file=new File("context.properties");
Scanner s=new Scanner(file);
while(s.hasNextLine()){
String temp=s.nextLine().trim();
if(temp.indexOf("=")>0){
String left=temp.substring(0,temp.indexOf("=")).trim();
String right=temp.substring(temp.indexOf("=")+1,temp.length()).trim();
if(left.equals("addr")) addr=right;
else if(left.equals("port")) port=Integer.parstInt(right);
else if(left.equals("username")) username=right;
else if(left.equals("pwd")) pwd=right;
}
}
}
public Test1 getSingleton(){
return test;
}
}
-------------------------
2:
class public Test2{
static private int i=0;
static public void add(){
i++;
}
static public void dec(){
i--;
}
}
public class A extends Thread{
public A(){
}
public void run(){
Test2.add();
}
}
public class B extends Thread{
public B(){
}
public void run(){
Test2.add();
}
}
public class C extends Thread{
public C(){
}
public void run(){
Test2.dec();
}
}
public class D extends Thread{
public D(){
}
public void run(){
Test2.dec();
}
}
-------------------
3.
public String substringByLast(String line,int last){
return line.substring(0,last);
}
--------------------
4.
student.js
var name;
var age;
var number;
function student(nameX,ageX,numberX){
name=nameX;
age=ageX;
number=numberX;
}
function say(){
alert('My name is'+name+',I am '+age+',My number is '+number;
}
5.
-------------------------
ls 显示目录下所有文件
cd 定位目录
mkdir rmdir 新建、删除目录
cp 复制文件
cat 显示txt文本文件
grep find 查找文件中字符串
6.
------------------------
SELECt avg(成绩) FROM 选课
WHERe 学号 IN(SELECt 学号 FROM 学生 WHERe 性别='男')
AND 课程号 IN(SELECt 课程号 FROM 课程 WHERe 课程名='语文')
SELECt max(成绩) FROM 选课
WHERe 学号 IN(SELECt 学号 FROM 学生 WHERe 性别='男')
AND 课程号 IN(SELECt 课程号 FROM 课程 WHERe 课程名='语文')
其他只需要修改
全部回答
- 1楼网友:三千妖杀
- 2021-04-12 11:37
第一题:
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
public class LoadConfig{
public HashMap getConfig(){
HashMap map = new HashMap();
File file = null;
BufferedReader br = null;
try{
file = new File("context.properties");
br = new BufferedReader(new FileReader(file));
String value = null;
String str = br.readLine();
while(str!=null){
value = str.substring(str.indexOf("=")+1);
if(str.startsWith("addr ")){
map.put("addr ",value);
}
if(str.startsWith("port ")){
map.put("port ",value);
}
if(str.startsWith("username ")){
map.put("username ",value);
}
if(str.startsWith("pwd")){
map.put("pwd",value);
}
str = br.readLine();
}
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}finally{
if (br!=null){
try{
br.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
return map;
}
}
第二题:
public class Start{
public static void main(String[] args){
ReturnJ rj = new ReturnJ();
rj.a();
while(true){
System.out.println (rj.j);
}
}
}
class ReturnJ{
public int j;
public void a(){
j=5;
OneThread one = new OneThread(this);
one.start();
TwoThread two = new TwoThread(this);
two.start();
ThreeThread three = new ThreeThread(this);
three.start();
FourThread four = new FourThread(this);
four.start();
}
}
class OneThread extends Thread{
ReturnJ rj;
public OneThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j++;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class TwoThread extends Thread{
ReturnJ rj;
public TwoThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j++;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class ThreeThread extends Thread{
ReturnJ rj;
public ThreeThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j--;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class FourThread extends Thread{
ReturnJ rj;
public FourThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j--;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
第三题:
public class Start{
public static String subStr(String strS,int i){
String strD = strS.substring(0,i);
int len = strD.length();
char c;
for(int j=0;j c = strD.charAt(j) ;
if(!(c>=0 && c<=127)){
len--;
}
if(i==len-1){
if(!(c>=0 && c<=127)){
len--;
}
}
}
return strD.substring(0,len);
}
public static void main(String[] args){
String str = subStr("我ABC汉DEF",6);
System.out.println (str);
}
}
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
public class LoadConfig{
public HashMap getConfig(){
HashMap map = new HashMap();
File file = null;
BufferedReader br = null;
try{
file = new File("context.properties");
br = new BufferedReader(new FileReader(file));
String value = null;
String str = br.readLine();
while(str!=null){
value = str.substring(str.indexOf("=")+1);
if(str.startsWith("addr ")){
map.put("addr ",value);
}
if(str.startsWith("port ")){
map.put("port ",value);
}
if(str.startsWith("username ")){
map.put("username ",value);
}
if(str.startsWith("pwd")){
map.put("pwd",value);
}
str = br.readLine();
}
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}finally{
if (br!=null){
try{
br.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
return map;
}
}
第二题:
public class Start{
public static void main(String[] args){
ReturnJ rj = new ReturnJ();
rj.a();
while(true){
System.out.println (rj.j);
}
}
}
class ReturnJ{
public int j;
public void a(){
j=5;
OneThread one = new OneThread(this);
one.start();
TwoThread two = new TwoThread(this);
two.start();
ThreeThread three = new ThreeThread(this);
three.start();
FourThread four = new FourThread(this);
four.start();
}
}
class OneThread extends Thread{
ReturnJ rj;
public OneThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j++;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class TwoThread extends Thread{
ReturnJ rj;
public TwoThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j++;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class ThreeThread extends Thread{
ReturnJ rj;
public ThreeThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j--;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
class FourThread extends Thread{
ReturnJ rj;
public FourThread(ReturnJ rj){
this.rj = rj;
}
public void run() {
while(true){
rj.j--;
try{
Thread.sleep(1000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
}
}
}
第三题:
public class Start{
public static String subStr(String strS,int i){
String strD = strS.substring(0,i);
int len = strD.length();
char c;
for(int j=0;j
if(!(c>=0 && c<=127)){
len--;
}
if(i==len-1){
if(!(c>=0 && c<=127)){
len--;
}
}
}
return strD.substring(0,len);
}
public static void main(String[] args){
String str = subStr("我ABC汉DEF",6);
System.out.println (str);
}
}
- 2楼网友:孤老序
- 2021-04-12 10:57
public class ConstainsFactory {
public static Properties proper = null;
static {
proper = new Properties();
InputStream in = ConstainsFactory.class.getResourceAsStream("/conf/context.properties ");//加载文件
try {
proper.load(in);//生成key_value对象
} catch (IOException e) {
e.printstack();
}
}
//根据key获得值
public static String getValue(String key){
String value = null;
if(key != null){
if(proper != null){
try {
value = proper.getProperty(key);
} catch (Exception e) {
value = null;
}
}
}
return value;
}
}
1. 对象初始化放在静态代码块里,只在第一此加载该类时运行,所有只有一个对象
2. Properties对象本身就是key_value形式的
public static Properties proper = null;
static {
proper = new Properties();
InputStream in = ConstainsFactory.class.getResourceAsStream("/conf/context.properties ");//加载文件
try {
proper.load(in);//生成key_value对象
} catch (IOException e) {
e.printstack();
}
}
//根据key获得值
public static String getValue(String key){
String value = null;
if(key != null){
if(proper != null){
try {
value = proper.getProperty(key);
} catch (Exception e) {
value = null;
}
}
}
return value;
}
}
1. 对象初始化放在静态代码块里,只在第一此加载该类时运行,所有只有一个对象
2. Properties对象本身就是key_value形式的
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯