java从键盘输入文字形成文件
1 //输入信息形成右边图示信息 2 package classwork10; 3 4 import java.io.BufferedWriter; 5 import java.io.File; 6 import java.io.FileWriter; 7 import java.io.IOException; 8 import java.util.Scanner; 9 10 public class Suruxx_jp { 11 12 public static void main(String[] args) throws IOException { 13 Scanner in=new Scanner(System.in); 14 String pathname="d:/sk1.txt"; 15 File f=new File(pathname); 16 FileWriter fw=null; 17 BufferedWriter bw=null; 18 fw=new FileWriter(f); 19 bw=new BufferedWriter(fw); 20 bw.write("姓名\t数学\t物理\t化学\t总成绩"); 21 bw.newLine(); 22 String xm; 23 int cj1,cj2,cj3,zcj,yes=1; 24 while(yes==1){ 25 System.out.println("请依次输入姓名 数学 物理 化学:"); 26 xm=in.next(); 27 cj1=in.nextInt(); 28 cj2=in.nextInt(); 29 cj3=in.nextInt(); 30 zcj=cj1+cj2+cj3; 31 bw.write(xm+"\t"+cj1+"\t"+cj2+"\t"+cj3+"\t"+zcj); 32 bw.newLine(); 33 System.out.println("继续添加学生吗?(1/0)"); 34 yes=in.nextInt(); 35 } 36 bw.close(); 37 fw.close(); 38 in.close(); 39 System.out.println("运行结束!"); 40 41 } 42 43 }

道阻且长,行则将至

浙公网安备 33010602011771号