java编写一个字符串,长度为三个字符,必须按顺序生成,从aaa到zzz

java编写一个字符串,长度为三个字符,必须按顺序生成,从aaa到zzz,第1张

import java.io.*

public class threeString {

public static void main(String[] args) throws Exception {

if (!(new File("D:\\threeString\\").isDirectory())) {

new File("D:\\threeString\\").mkdir()

}

File tofile = new File("D:\\threeString\\temp.txt")

if (!tofile.exists()) {

tofile.createNewFile()

}

String lastLine = readLastLine(tofile, "utf-8").replace("\n", "")

System.out.println(lastLine)

if (lastLine != null && lastLine != "zzz") {

String newLine = ""

if (lastLine == null || lastLine == "") {

newLine = "aaa\n"

} else {

newLine = stringPP(lastLine)//自己实现下

}

BufferedWriter writer = new BufferedWriter(new FileWriter(new File(

"D:\\threeString\\temp.txt"), true))

writer.append(newLine)

writer.flush()

writer.close()

}

}

public static String stringPP(String s) {//字符递增,考虑转成16进制后+1,再转成字符串,转换函数写好了

return s

}

public static String toHexString(String s) {

String str = ""

for (int i = 0 i < s.length() i++) {

int ch = (int) s.charAt(i)

String s4 = Integer.toHexString(ch)

str = str + s4

}

return str

}

public static String toStringHex(String s) {

byte[] baKeyword = new byte[s.length() / 2]

for (int i = 0 i < baKeyword.length i++) {

try {

baKeyword[i] = (byte) (0xff & Integer.parseInt(

s.substring(i * 2, i * 2 + 2), 16))

} catch (Exception e) {

e.printStackTrace()

}

}

try {

s = new String(baKeyword, "utf-8")// UTF-16le:Not

} catch (Exception e1) {

e1.printStackTrace()

}

return s

}

public static String readLastLine(File file, String charset)

throws IOException {

if (!file.exists() || file.isDirectory() || !file.canRead()) {

return null

}

RandomAccessFile raf = null

try {

raf = new RandomAccessFile(file, "r")

long len = raf.length()

if (len == 0L) {

return ""

} else {

long pos = len - 1

while (pos > 0) {

pos--

raf.seek(pos)

if (raf.readByte() == '\n') {

break

}

}

if (pos == 0) {

raf.seek(0)

}

byte[] bytes = new byte[(int) (len - pos)]

raf.read(bytes)

if (charset == null) {

return new String(bytes)

} else {

return new String(bytes, charset)

}

}

} catch (FileNotFoundException e) {

} finally {

if (raf != null) {

try {

raf.close()

} catch (Exception e2) {

}

}

}

return null

}

}

文件太大,给你代码,你自己运行吧,结果保存到C:\1.txt。

Private Sub Form_Load()

Dim I As Integer, j As Integer, k As Integer

Open "c:\1.txt" For Output As #1

For I = 97 To 122

For j = 97 To 122

For k = 97 To 122

Print #1, Chr(I)Chr(j)Chr(k)

Next: Next: Next

Close

End

End Sub

A1输入:

="1"&CHAR(96+IF(MOD((ROW()-1)/676,26)+1=0,26,MOD((ROW()-1)/676,26)+1))&CHAR(96+IF(MOD((ROW()-1)/26,26)+1=0,26,MOD((ROW()-1)/26,26)+1))&CHAR(96+IF(MOD(ROW(),26)=0,26,MOD(ROW(),26)))

选A1,下拉到17576行

就可以列出所有组合


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12201982.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存