Java i/o 问题?

来源:百度知道 编辑:UC知道 时间:2024/09/21 18:46:35
import java.io.*;
public class shuru1{
InputStream s=System.in;
public void A()throws IOException{

InputStreamReader f= new InputStreamReader(s);
BufferedReader br=new BufferedReader(f);
int num = Integer.parseInt(br.readLine());
int m=num+1;
System.out.println(m);
}
public void B()throws IOException{
byte[] a= new byte[256];
int c=s.read(a);
for(int i=c-2;i>=0;i--)
System.out.print((char)a[i]);
}
public static void main(String args[])throws IOException{

shuru1 sr=new shuru1();
sr.A();
sr.B();

}
}
请先看这个程序,有没有可能从键盘输入一个数然后让A和B同时执行?如果可能的话,该怎么做?还有有没有可能让A执行过后再执行B,但是B所引用的数是A执行后的结果?简单点说就是我从键盘输入一个数,然后得出的结果是这个数加1后的反输出,例如我输入123,那么他的输出结果就应该是421,自己想不到该怎么做,请教高手。
yeskeesky 能解释一下你添加的那三行代码吗?<

你用这段试试:

import java.io.*;
public class shuru1{
InputStream s=System.in;
public void A()throws IOException{

InputStreamReader f= new InputStreamReader(s);
BufferedReader br=new BufferedReader(f);
int num = Integer.parseInt(br.readLine());
int m=num+1;
String s = String.valueOf(m) ;
StringBuffer sb=new StringBuffer(s);
System.out.println(sb.reverse());
}
public void B()throws IOException{
byte[] a= new byte[256];
int c=s.read(a);
for(int i=c-2;i>=0;i--)
System.out.print((char)a[i]);
}
public static void main(String args[])throws IOException{

shuru1 sr=new shuru1();
sr.A();
sr.B();

}
}
-----------------
我在我电脑上试过.
输出结果和你的要求一样.

你试一下.有问题再提!!!

多线程编程

import java.io.*;
public class shuru1{
InputStream s=System.in;
public void A()throws IOException{

InputStreamRead