A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 你好,师姐 中级黑马   /  2016-12-9 00:25  /  862 人查看  /  1 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

package cn.itcast05;

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;

/*
* 使用键盘录入  录入 学生姓名 和年龄     
*     录入三个学生对象  
*     
*   把学生存到 文档中
*       一行一行存
*/
public class Test2 {
        public static void main(String[] args) throws Exception {
                Scanner sc = new Scanner(System.in);
                BufferedWriter bw = new BufferedWriter(new FileWriter("c.txt"));
                for (int i = 1; i <= 3; i++) {
                        System.out.println("请输入第" + i + "个人的姓名");
                        String s = sc.next();
                        System.out.println("请输入第" + i + "个人的姓名");
                        int s1 = sc.nextInt();

                        bw.write(s + s1);
                        bw.newLine();

                }

                bw.close();

                // ArrayList<Student>stu = new ArrayList<Student>();
                // Student s = new Student();
                /*
                 * for(int i= 0;i<3;i++){ String s1= sc.next(); s1=
                 * stu.add(s.getName()+s.getAge());
                 *
                 * }
                 */
                /*
                 * BufferedWriter bw = new BufferedWriter(new FileWriter("c.txt"));
                 *
                 * stu.add(new Student("张飞",12)); stu.add(new Student("李逵",13));
                 * stu.add(new Student("张辽",15));
                 *
                 * for (Student s : stu) { bw.write(s.getName()+s.getAge());
                 * bw.newLine(); //System.out.println(s.getAge()+s.getName());
                 *
                 * }
                 */

                /*
                 * Scanner sc = new Scanner(System.in ); for (int i = 0; i < 3; i++) {
                 * System.out.println("请输入第"+i+1+"个学生姓名");
                 */

        }

}


1 个回复

倒序浏览
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马