java编程10. 编写九九乘法口诀表,并写入到D:\99.txt文件中 将一个99乘法表输出到文件中,用java编写!要用到流!亲!...

java\u7f16\u7a0b\u5c06\u4e00\u4e2a99\u4e58\u6cd5\u8868\u8f93\u51fa\u5230\u6587\u4ef6\u4e2d

package controller;
import java.io.*;
public class IODemo {
public static void main(String[] args)throws IOException {
File file = new File("d:/\u4e5d\u4e5d\u4e58\u6cd5\u8868.txt");
OutputStream output = new FileOutputStream(file);
String str = "";
for(int i=1;i<10;i++){
for(int j=1;j<=i;j++){
str+=j+"*"+i+"="+i*j+"\t";
}
str+="\r\n";
}
System.out.println(str);
output.write(str.getBytes());
System.out.println("\u5199\u5165\u6210\u529f\uff01");
//\u4e0d\u7528\u4e86\u8bb0\u5f97\u5173\u6389
output.close();
}
}


package com.bozhong.dto;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class WriteFile {

public static void main(String[] args) {
StringBuffer stringBuffer = new StringBuffer("\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff1a\r\n");
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
stringBuffer.append(i + "*" + j + "=" + i * j + " ");
}
stringBuffer.append("\r\n");
}
String str = stringBuffer.toString();
System.out.println(str);
File txt = new File("d:\\\u4e5d\u4e5d\u4e58\u6cd5\u8868.txt");
if (!txt.exists()) {
try {
txt.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
byte bytes[] = new byte[512];
bytes = str.getBytes();
int b = str.length();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(txt);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fos.write(bytes, 0, b);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
\u5b8c\u5168\u6ee1\u8db3\u4e86\u4f60\u7684\u9700\u6c42\uff01

public class Test {

public void math1(int j){
try {
//FileWriter fw = new FileWriter("D:\\99.txt",true);
FileOutputStream fw=new FileOutputStream("D:\\99.txt",true);
String sb="";
for (int i = 1; i<=j ;i++ )
{
System.out.print(j+"*"+i+"="+(j*i)+" ");
sb+=(j+"*"+i+"="+(j*i)+" ");
}
if(j<9){
System.out.println("");
sb+="\r\n";
// fw.write(sb);
byte[] object = sb.getBytes();
fw.write(object);
fw.flush();
fw.close();
math1(j+1);
}else{
sb+="\r\n";
// fw.write(sb);
byte[] object = sb.getBytes();
fw.write(object);
fw.flush();
fw.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public static void main(String[] args)
{
Test t = new Test();
t.math1(1);
}

}

1×1=1   1×2=2 2×2=4   1×3=3 2×3=6 3×3=9   1×4=4 2×4=8 3×4=12 4×4=16   1×5=5 2×5=10 3×5=15 4×5=20 5×5=25   1×6=6 2×6=12 3×6=18 4×6=24 5×6=30 6×6=36   1×7=7 2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49   1×8=8 2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64   1×9=9 2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81

11的112得13得314得

扩展阅读:黑马java视频 ... 免费学java编程的网站 ... java编程常用软件 ... java初学编程100个代码 ... 学java一般能干什么 ... 从零开始学java编程 ... java实战项目大全 ... java编程试题及答案 ... java高级编程入门 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网