gpt4 book ai didi

java - IntelliJ 仅打印所需输出的一部分(Java)

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:24 25 4
gpt4 key购买 nike

我希望以前没有人问过这个问题,如果有的话,我们深表歉意,并提前感谢您的帮助!

问题:以下程序将文件拆分为序列,计算序列中的字母并使用这些数字执行计算。我正在检查文件是否被正确分割,通过使用循环打印它们,似乎某些循环只打印所需输出的一部分。我意识到这不是一个主要错误,但无法找出问题所在让我很恼火。

注意:这是一项大学作业,因此存在一些限制,这就是代码不干净的原因。

这是我的代码:

public String cryptanalysis() throws IOException {
// Please, do not remove the editor-fold comments.
//<editor-fold defaultstate="collapsed" desc="Write your code here below!">


//</editor-fold> // END OF YOUR CODE
//use this for IOC

int period = 7; //possible key lengths

for (int i = 1; i < period + 1; i++) {
Util util = new Util();
System.out.println("Period = " + i);

String sequences[] = new String[i]; //broken up strings

for (int a = 0; a < sequences.length; a++) {
sequences[a] = "";
}
int sequenceCounter = 0;


for (int j = 0; j < ciphertext.length(); j++) {
sequences[sequenceCounter] = sequences[sequenceCounter] + ciphertext.charAt(j);
sequenceCounter++;

if (sequenceCounter == sequences.length) {
sequenceCounter = 0;
}
}

double[] indexOfCoincidences;
indexOfCoincidences = new double[i];
double sumOfIndexOfCoincidences = 0.0;

for (int k = 0; k < indexOfCoincidences.length; k++) {
//System.out.println("Sequence" + k + " - " + sequences[k]);
indexOfCoincidences[k] = util.calculateIOC(sequences[k]);
System.out.println("Sequence 0 - " + sequences[0]);
System.out.println("IOC of sequence " + k + " - " + indexOfCoincidences[k]);
sumOfIndexOfCoincidences = sumOfIndexOfCoincidences + indexOfCoincidences[k];
}

double averageIndexOfCoincidence = sumOfIndexOfCoincidences/indexOfCoincidences.length;
//System.out.println(indexOfCoincidences.length);
System.out.println("IOC " + indexOfCoincidences.length + " = " + averageIndexOfCoincidence);

}

这是输出(我已经突出显示了问题):

Period = 1
Sequence 0 - vptnvffuntshtarptymjwzirappljmhhqvsubwlzzygvtyitarptyiougxiuydtgzhhvvmum
shwkzgstfmekvmpkswdgbilvjljmglmjfqwioiivknulvvfemioiemojtywdsajtwmtcgluy
sdsumfbieugmvalvxkjduetukatymvkqzhvqvgvptytjwwldyeevquhlulwpkt

IOC of sequence 0 - 0.044944352356144926

IOC 1 = 0.044944352356144926

Period = 2

ssmbegvlxjutktmkzvvvttwlyeqhuwk <- Section of output missing

IOC of sequence 0 - 0.04492670854749667

ssmbegvlxjutktmkzvvvttwlyeqhuwk <- Section of output missing

IOC of sequence 1 - 0.046640015229392734

IOC 2 = 0.0457833618884447

Period = 3

hztemsgllgjwiklfiejwawcu <- Section of output missing

sfemlkuutvzqvywdeuup <- Section of output missing

IOC of sequence 0 - 0.036435469710272166

hztemsgllgjwiklfiejwawcu <- Section of output missing

sfemlkuutvzqvywdeuup <- Section of output missing

IOC of sequence 1 - 0.045609548167092936

hztemsgllgjwiklfiejwawcu <- Section of output missing

sfemlkuutvzqvywdeuup <- Section of output missing

IOC of sequence 2 - 0.04901960784313726

IOC 3 = 0.04368820857350079

Period = 4

wsepdljmwiufoowjtusmevxukmzvtwyquk <- Section of output missing

IOC of sequence 0 - 0.04072398190045249

wsepdljmwiufoowjtusmevxukmzvtwyquk <- Section of output missing

IOC of sequence 1 - 0.03846153846153847

wsepdljmwiufoowjtusmevxukmzvtwyquk <- Section of output missing

IOC of sequence 2 - 0.04862745098039216

wsepdljmwiufoowjtusmevxukmzvtwyquk <- Section of output missing

IOC of sequence 3 - 0.05568627450980392

IOC 4 = 0.04587481146304676

Period = 5

Sequence 0 - vfspwphuzypuyhuhsksijjonfitatysivktyzgtdql

IOC of sequence 0 - 0.04065040650406503

Sequence 0 - vfspwphuzypuyhuhsksijjonfitatysivktyzgtdql

IOC of sequence 1 - 0.04146341463414635

Sequence 0 - vfspwphuzypuyhuhsksijjonfitatysivktyzgtdql

IOC of sequence 2 - 0.048717948717948725

Sequence 0 - vfspwphuzypuyhuhsksijjonfitatysivktyzgtdql

IOC of sequence 3 - 0.0451219512195122

Sequence 0 - vfspwphuzypuyhuhsksijjonfitatysivktyzgtdql

IOC of sequence 4 - 0.04181184668989547

IOC 5 = 0.04355311355311356

Period = 6

zeslgwkfewwuselutzvweu

IOC of sequence 0 - 0.0427807486631016

zeslgwkfewwuselutzvweu

IOC of sequence 1 - 0.04991087344028521

zeslgwkfewwuselutzvweu

IOC of sequence 2 - 0.058823529411764705

zeslgwkfewwuselutzvweu

IOC of sequence 3 - 0.030303030303030297

zeslgwkfewwuselutzvweu

IOC of sequence 4 - 0.052100840336134456

zeslgwkfewwuselutzvweu

IOC of sequence 5 - 0.04369747899159665

IOC 6 = 0.04626941685765216

Period = 7

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 0 - 0.04926108374384236

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 1 - 0.0367816091954023

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 2 - 0.07142857142857142

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 3 - 0.04679802955665024

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 4 - 0.06206896551724138

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 5 - 0.041379310344827586

Sequence 0 - vurzjugrggukewjjivedt

bauyvyyl

IOC of sequence 6 - 0.059113300492610835

IOC 7 = 0.052404410039878016

最佳答案

我明白了!如果将来有人遇到此问题,请确保您正在使用的文件中的文本全部在一行上。

关于java - IntelliJ 仅打印所需输出的一部分(Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52764399/

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