java线程笔试代码题,java线程编程题
Java关于io和多线程的编程题,求代码
package know;
网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了奎文免费建站欢迎大家使用!
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class T20 {
public static void main(String[] args) throws IOException {
Scanner s=new Scanner(System.in);
String username=null;
String password=null;
System.out.println("输入用户名:");
while(true){
if(username==null){
username=s.next();
System.out.println("输入密码:");
}else{
password=s.next();
}
if(password!=null){
s.close();
break;
}
}
BufferedReader br=null;
MapString, String map=new HashMapString, String();
try{
br=new BufferedReader(new InputStreamReader(new FileInputStream("d:/test.txt")));
String temp=null;
while((temp=br.readLine())!=null){
String[] ss=temp.split("=");
map.put(ss[0], ss[1]);
}
}catch(IOException e){
throw e;
}finally{
if(br!=null)
br.close();
}
String u=map.get("userName");
String p=map.get("password");
if(u.equals(username)p.equals(password)){
System.out.println("登录成功");
}else{
System.out.println("用户名或密码错误");
}
}
}
package know;
public class T21 {
public static void main(String[] args) throws InterruptedException {
String[] persons=new String[]{"甲","乙","丙","丁","午","己","庚","辛","壬","癸"};
for(int i=0;ipersons.length;i++){
System.out.println(persons[i]+"正在过山洞");
Thread.sleep(5000);
}
}
}
最后一个百度搜一个就行了,肯定比我画的好
java题目 编程题目 多线程
public class DoubleThread {
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
for (char i = 'a'; i = 'z'; i++) {
System.out.println(i);
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
for (char i = 'A'; i = 'Z'; i++) {
System.out.println(i);
}
}
};
t1.start();
t2.start();
}
}
java关于线程的题两道- -
public class ThreadTest {
public static void main(String[] args) {
// ================Q1 START================
SubThread T1 = new SubThread("Frist");
SubThread T2 = new SubThread("Second");
SubThread T3 = new SubThread("Third");
T1.start();
T2.start();
T3.start();
// ================Q1 FINISHED================
// ================Q2 START================
// MulThread mThread = new MulThread();
// Thread t1 = new Thread(mThread);
// Thread t2 = new Thread(mThread);
// Thread t3 = new Thread(mThread);
// t1.setName("t1");
// t2.setName("t2");
// t3.setName("t3");
// t1.start();
// t2.start();
// t3.start();
// ================Q2 FINISHED================
}
}
class MulThread implements Runnable {
public MulThread() {
}
public MulThread(String name) {
}
public synchronized void run() {
System.out.println("currentThread Name is "
+ Thread.currentThread().getName());
long sleeptime = (long) new Random().nextInt(1000);
//System.out.println((int)(Math.random() * 1000));
// System.out.println("sleeptime " + sleeptime);
// System.out.println("--------------------------------");
try {
Thread.sleep(sleeptime);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Q2:MulThread info : "
+ Thread.currentThread().getName() + " finished");
}
}
class SubThread extends Thread {
public SubThread(String name) {
super(name);
}
public synchronized void run() {
for (int i = 0; i 5; i++) {
System.out.println("Thread " + this.getName() + " is running the "
+ (i + 1) + " times");
try {
long sleeptime = (long) new Random().nextInt(1000);
// System.out.println("sleeptime " + sleeptime);
Thread.sleep(sleeptime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Q1:SubThread info : "
+ this.currentThread().getName() + " finished");
}
}
java笔试题:从线程和安全说一下sleep()和wait()的区别
这两者的施加者是有本质区别的.
sleep()是让某个线程暂停运行一段时间,其控制范围是由当前线程决定,也就是说,在线程里面决定.好比如说,我要做的事情是 "点火-烧水-煮面",而当我点完火之后我不立即烧水,我要休息一段时间再烧.对于运行的主动权是由我的流程来控制.
分享名称:java线程笔试代码题,java线程编程题
网页路径:http://scyanting.com/article/hdoioe.html