黑马程序员技术交流社区
标题:
*赠人玫瑰,手有余香*-----[io小例子]
[打印本页]
作者:
驰骋向前
时间:
2016-12-9 00:22
标题:
*赠人玫瑰,手有余香*-----[io小例子]
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
/*
* 使用键盘录入 录入 学生姓名 和年龄
* 录入三个学生对象
*
* 把学生存到 文档中
* 一行一行存
*/
public class student {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
BufferedWriter bw = new BufferedWriter(new FileWriter("student.txt"));
int i=0;
while (i<3) {
System.out.println("请输入学生姓名");
String s = sc.next();
System.out.println("请输入学生年龄");
String s1 = sc.next();
bw.write(s+"年龄是"+s1);
bw.newLine();
bw.flush();
}
bw.close();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2