如题,有两个变量int x=100,y=200,用一个程序实现两个线程,第一个线程是x加1,第二个线程功能是y减1。
在线等,有劳各位啦

解决方案 »

  1.   

    private static int x = 100;
    private static int y = 200;public static void main(String[] args)
    {
        new Thread(){public void run(){while(true){x++;}}}.run();
        new Thread(){public void run(){while(true){y--;}}}.run();
    }
      

  2.   

    粗心
    private static int x = 100;
    private static int y = 200;public static void main(String[] args)
    {
        new Thread(){public void run(){while(true){x++;}}}.start();
        new Thread(){public void run(){while(true){y--;}}}.start();
    }