1.键盘输入10个数,放到数组中
a. 去除该数组中大于10的数
b. 将该数组中的数字写入到本地文件number.txt中- public class Test1 {
- static int[] arr = new int[10];
- public static void main(String[] args) throws IOException {
- saveNumber();
- writeTxt();
- }
- private static void writeTxt() throws IOException {
- BufferedWriter bufw = new BufferedWriter(new FileWriter("number.txt"));
- for (int i = 0; i < 10; i++) {
- if(arr[i]<10){
- bufw.write(arr[i]);
- bufw.flush();
- }
- }
- }
- public static void saveNumber() {
- Scanner sc = new Scanner(System.in);
- for (int i = 0; i < arr.length; i++) {
- System.out.println("请您输入第"+(i+1)+"个数字");
- arr[i] = sc.nextInt();
- }
- System.out.println("输入完毕!");
- }
- }
复制代码
运行结果txt文件上是乱码 |
|