import java.io.*;public class Reverse
{
public static void main(String args[])
{
int i, n = 10;
int a[] = new int [10]; for ( i = 0; i < n; ++i ) {
try {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine()); } catch ( IOException e ){};
} for ( i = n - 1; i >= 0; --i) {
System.out.print(a[i]+" ");
}
System.out.println();
}
}这段代码编译没有问题,但是运行的时候出了错误?不知道哪里错了?创建两个Thread类对象,第一个对象的字符串为“XX学院”,暂停时间 为50毫秒,第二个对象的字符串为“母校明天更美好”,暂停时间为100毫秒,分别激活这两个线程,每个线程被执行20次。利用实现Runnable接口创建线程。汗,还没看到线程,要写线程的题目,不会写啊。
{
public static void main(String args[])
{
int i, n = 10;
int a[] = new int [10]; for ( i = 0; i < n; ++i ) {
try {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine()); } catch ( IOException e ){};
} for ( i = n - 1; i >= 0; --i) {
System.out.print(a[i]+" ");
}
System.out.println();
}
}这段代码编译没有问题,但是运行的时候出了错误?不知道哪里错了?创建两个Thread类对象,第一个对象的字符串为“XX学院”,暂停时间 为50毫秒,第二个对象的字符串为“母校明天更美好”,暂停时间为100毫秒,分别激活这两个线程,每个线程被执行20次。利用实现Runnable接口创建线程。汗,还没看到线程,要写线程的题目,不会写啊。
{
public static void main(String args[])
{
int i, n = 10;
int a[] = new int [10];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for ( i = 0; i < n; ++i )
{
try
{
a[i] = Integer.parseInt(br.readLine());
}
catch ( IOException e )
{};
}
for ( i = n - 1; i >= 0; --i)
{
System.out.print(a[i]+" ");
}
System.out.println();
}
}
public class Test
{
public static void main(String[] args)
{
new Thread(new FirstRunnable()).start();
new Thread(new SecondRunnable()).start();
}
}class FirstRunnable implements Runnable
{
public void run()
{
for (int i = 0; i < 20; i++)
{
System.out.println("XX学院");
try
{
Thread.sleep(50);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}class SecondRunnable implements Runnable
{
public void run()
{
for (int i = 0; i < 20; i++)
{
System.out.println("母校明天会更好");
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}