16周作业

题目一

package com;
import java.text.SimpleDateFormat;
import java.util.Date;
public class thread implements Runnable{
    Date date;
    public void run() {
        while(true){
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
            String time = sdf.format(date);
            System.out.println(time);
            try{
                Thread.sleep(1000);
            }catch(InterruptedException e){
                System.out.println(e);
            }
        }
        
        
  
    }
}
package com;

import java.util.Scanner;

public class currenttime {
    

    public static void main(String[] args) {
        Thread t=new Thread(new thread() );
        t.start();
    }

}

 题目二

package com;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class thread implements Runnable{
    Scanner s=new Scanner(System.in);
    int flag;
    public void run() {
        while(true){
            System.out.println("请输入数字");
            int c=s.nextInt();
            int a=(int)(Math.random()*100);
            if(c>=a){
                System.out.println("你的数字猜大了");
            }else if(c<a)
                System.out.println("你猜的数字小了,");
            else System.out.println("恭喜你,猜对了");
         //   System.out.println(a);
            try{
                Thread.sleep(1000);
              
                
            }catch(InterruptedException e){
                System.out.println(e);
            }
       
        }
        
        
  
    }
}
package com;

import java.util.Scanner;

public class currenttime {
    

    public static void main(String[] args) {
        Thread t=new Thread(new thread() );
        t.start();
    }

}

猜你喜欢

转载自www.cnblogs.com/chenxiangyuu/p/12076818.html
今日推荐