gpt4 book ai didi

java - 如何在控制台中每行打印特定数量的字符?

转载 作者:行者123 更新时间:2023-12-01 09:26:06 26 4
gpt4 key购买 nike

我正在尝试在控制台中每行打印 80 个字符。我可以每行打印 80 个字符,但是当字符串中剩余的字符少于 80 个时,它们不会被打印。我该如何解决这个问题?

public void output(String plainText, String cipherText, String iv, String key, String filename) {
System.out.println("CBC Vigenere by ");
System.out.println("Plaintext file name: " + filename);
System.out.println("Vigenere Keyword: " + key);
System.out.println("Initialization vector: " + iv + "\n");
//This is the code for printing 80 char per line
System.out.println("Clear Text: \n");
int j = 0;
String output = "";
for (int i = 0; i < plainText.length(); i++) {
j++;
output = output + plainText.charAt(i);
if (j == 80) {
System.out.println(output);
output = "";
j=0;
}else{
//an attempt to print the remaining characters
// System.out.println(output);
}


}
//same process as above.
System.out.println(" \n Cipher Text:\n ");
j = 0;
output = "";
for (int i = 0; i < cipherText.length(); i++) {
j++;
output = output + cipherText.charAt(i);
if (j == 80) {
System.out.println(output);
output = "";
j = 0;

} else if ((cipherText.length() - i) <= 80) {
if (j == 80) {
if (j == (cipherText.length() - i)) {
//if (j == 80) {
System.out.println(output);
output = "";
j = 0;
System.out.println((output));

j = 0;
}
}
}
}
System.out.println("\n\nNumber of characters in clean plaintext file: " + (plainText.length() - padding));
System.out.println("Block Size: " + key.length());
System.out.println("Number of pad Characters added: " + padding);

}

输出:

 Clear Text:

csthesciencethatdealswiththetheoryandmethodsofprocessinginformationindigitalcomp
utersthedesignofcomputerhardwareandsoftwareandtheapplicationsofcomputersitthedev
elopmentimplementationandmaintenanceofcomputerhardwareandsoftwaresystemstoorgani
zeandcommunicateinformationelectronicallyabbreviationitcomputersaremanmadetoolst
hataidusinsolvingotherproblemsabiologististryingtofigureouthowlifeworksphysicist
sandchemistsaretryingtofigureouthowitemsreactinouruniversemathematiciansaretryin
gtofigureoutrulesformanmadesystemsanyresearchproblemthatmayimproveacomputerscapa
bilityofhelpingsolveaproblemoranyresearchproblemthatshedslightaboutanewwaytodoso
methingwithacomputerispartofcsmostexcitingresearchmedicalapplicationsexpertsyste
msfordiagnosisremotesurgerynanodeviceswithcomputingpowertodelivermedicineetcwene
edhelptryingtocreateacomprehensiveemraccessibletotherightpeopleonlycarsthatcandr
ivethemselvesseemslikethebestwayweknowhowtosolvelotsofproblemsisbythrowinglotsof
computingpowerattheminsteadoflookingforelegantsolutionsthisdoesntsoundexcitingbu
titwillbeexcitingwhentheresultsareachievediewatsoncsstudentstendtofindjobswheret
heyprogramatleastsomeintheprocesstheyaresolvingproblemschallengesitsimpossibleto
teachallthenewlanguagestoysultimatelywejustneedtoteachourstudentshowtothinksotha
ttheycanpickupnewthingsontheirownourbiggestchallengeisgettingthemtobuyintothatet

Cipher Text:

qiqxbxknvieuejlkvwcpbtquevshswdsbyitsndorkbkwxswngygxwrkgfsbqvxwmsgiatpheilbuxnu
ovzuyvmhwtvjiedrmnfkglrkfsddglexlsvsqfqjxiiqcbcqnyjvblktkjfeeaqklehghsfsutuiftqw
bpwmpyjzytumfgqbqjqzluspcjjzdaovvqeczpilbicjnibqzbcjavhqrqmdmhtgegjgjscscoxnkvel
kxrsbcwwpyjoswsihdtzrtyunqhczoipglabjjbcgkotmfovvwkseieszmvovataazltsolwviveqxpy
dgdosztziuhqztoobkbzmyixdgvsosvbkxctpjokdkdjizcncjozbbznupuepihytkwguytvhbgrphoi
nqhbqqbkqkqkxjikgqvlimdzsntmeifjtfwvwhphntudutoppoqjfmqlpxifiutoappzehyhfgqhondi
qjlwakbjmfngliduchxgqokirtcththfafhamzxzihgruoskadlxlmsnlvqljihejqqaluhwhifioqky
sokekkfxtjlgabnbiukgrdpzxsimdlkgpfaflnjxxuvqdjodosvtuiftemtahbokjmjudggknqnmxiwe
pqpfearegfundjwgxhigxgtorpmcvcoynzyehuhkbyzkywfvokhwrmauscozgppxpnkijunryqyqdqdc
wciygjvrimdmsmqyjujgiigwrvwqdlywjzyjjjmzmovkohpiedramexdxzhlzbbnzhkszcoxzjztcfwr
hcvonlnksamomkvjgrgdnnihegpvaqzgbsmmkuteeedulnworpfbdrqgqdbzxsiochhroqnrbzbjiesd
hgshgtztkmmylywkpkhaymybjkukuobuegvbqfebhcccxvzhrdrdmqipdyvkokdklqlfjbmrgfybybto
ckvhwildyateedleltwnlikjvrfnrgmcdsxgjchozamigjffxhxxssrtfjeuzgybybtdnoythjhzbnjp
jfjjycqlbxfhuijdwhkteusgqspuhvgdeplzzpksvdkpnxnxisrsqtreczczclwwwsiictspapdeodze
nqsnqjdikcrdjpqpqpljwzqaemalvvgvfwtiyqwcvynbcwptnpvigcfmtulnwijuikikxetasahjzvzr
zdgnuvmomdxyicakuyvgishtczbbtciwpxaqfuqlrlrgcsmthuscbrwtutuvehyixxsbsxsmhhyhtihq
hrvdanhidymqnnhzkayqseralbznomjqdmelmbzpkpkzyhqabvohdhqtqufpsqgczdumvsknkjkyrzca

我缺少字符串中的最后 20 个字符。添加它们的实用方法是什么?字符串大小会有所不同,因此其大小并不总是相同。

最佳答案

如果 for 循环完成后 output 不为空,则打印它。

关于java - 如何在控制台中每行打印特定数量的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39819676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com