给点提示,象这样:
import java.io.*;public class Echo {
public static void main(String[] args) {
DataInputStream in =
new DataInputStream(
new BufferedInputStream(System.in));
String s;
try {
while((s = in.readLine()).length() != 0)
if(1 == Integer.parseInt(s)){
System.out.println("this is 1");
}else if(2 == Integer.parseInt(s)){
System.out.println("this is 2");
}
System.out.println(s);
// An empty line terminates the program
} catch(IOException e) {
e.printStackTrace();
}
}
}
//////////////
该知道怎么做了吧!
import java.io.*;public class Echo {
public static void main(String[] args) {
DataInputStream in =
new DataInputStream(
new BufferedInputStream(System.in));
String s;
try {
while((s = in.readLine()).length() != 0)
if(1 == Integer.parseInt(s)){
System.out.println("this is 1");
}else if(2 == Integer.parseInt(s)){
System.out.println("this is 2");
}
System.out.println(s);
// An empty line terminates the program
} catch(IOException e) {
e.printStackTrace();
}
}
}
//////////////
该知道怎么做了吧!
Sting s;
try
{
BufferedReader in=
new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
i=Integer.parseInt(s);
}catch (IOException e){}
用这段代码很容易的就可以将输入的数转换为int 型。
上面的i就输出时就是一个数。
另外,上面的问题用选择法
switch{}
应该很好解决的!