以随机产生大写字母为例,执行代码后文档中有n行m列大写数字
以下为示例代码

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
public class filewr {
	public static void main(String[] args) {
		  // TODO Auto-generated method stub
	Scanner sc=new Scanner(System.in);
 	 Random r1 = new Random(); //随机数
 	r1.setSeed(100);
 	 File f1=new File("C:/Users/ASUS/Documents/java/Ten","f11.text");//创建文件对象
	if(!f1.exists()){//判断文件是否存在
  	 try {
		f1.createNewFile();//若不存在则创建文件
 	  } catch (IOException e) {
		e.printStackTrace();
		}
	}
	try {
 	  FileWriter fw = new FileWriter(f1.getPath());//得到所写文件的路径
 	  	 int n = sc.nextInt();//输入行
        		 int m = sc.nextInt();//输入列
       	  for (int i = 1; i <= n; i++) {
        		 String s = "";
 //代码填空第1行,m作为循环变量的循环结构 
 	 for (int a = 1; a <= m; a++){
 //代码填空第2行,给x赋值,x为65到90之间的一个随机整数 
 	 x=r1.nextInt(26)+65;
              s = s + (char)x;
               }  
         fw.write(s+"\n");//输入到文件中
         }
              fw.close();
 	 } catch (IOException e) {
 		 e.printStackTrace();
 		 }
 	 }
  }

以下为执行代码后文档中的内容
利用java在文档中输入

相关文章:

  • 2022-12-23
  • 2021-07-19
  • 2022-02-18
  • 2021-08-14
  • 2021-08-14
  • 2021-11-10
  • 2021-08-23
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2021-10-17
  • 2021-06-18
  • 2021-11-22
相关资源
相似解决方案