package shiti1013;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class 多个整数倒叙打印 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("请输入多个整数,按end键结束");
StringBuffer sb = new StringBuffer();
while(true){
String line = sc.nextLine();
if ("end".equals(line)) {
break;
}
try {
Integer.parseInt(line);
char[] ch = line.toCharArray();
for (int i = ch.length-1; i >=0 ; i--) {
sb.append(ch[i]+"");
}
sb.append(" ");
} catch (Exception e) {
System.out.println("您的输入有误");
}
}
System.out.println(sb);
String string = new String(sb);
byte[] bytes = string.getBytes();
FileOutputStream fos = new FileOutputStream("bum.txt");
fos.write(bytes);
fos.close();
}
}
|
|