gpt4 book ai didi

java - 线程 “main” 中的异常 java.util.IllegalFormatConversionException : g ! = java.lang.String

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:55:42 28 4
gpt4 key购买 nike

<分区>

我对 java 有点陌生,希望有人能帮助我。我正在使用文本编辑器在虚拟机 Ubuntu 上编写这段代码。如果您想引用该文件,RAM 错误就在这里。 http://users.cis.fiu.edu/~crahn/CGS3767/RAMerrors .错误位于 System.out.printf 中的 public static readingLine。如果有人能帮我找出错误,我将不胜感激。谢谢!

import java.io.*;
import java.util.*;


public class MemoryCalculator
{
private static Scanner convertingFiles;
public static String convertFile = "RAMerrors.txt";

public static void readFile(String nameOfFile) throws IOException
{
convertingFiles = new Scanner(new File(nameOfFile));
}

public static void readingLine(String nameOfFile) throws IOException
{
System.out.println();
int recordingNum = 0;
while(convertingFiles.hasNext())
{
recordingNum = recordingNum +1;
String recordingLine = convertingFiles.nextLine();

System.out.printf("( %d) %g ) \n", recordingNum, recordingLine );
String conv = fromHexToBi(recordingLine);
long decimal = fromBiToDec(conv);
System.out.println(errorRamRangeWeb(decimal));
}
}

public static String fromHexToBi(String input)
{

int fromHexToBi = 0;
String record = "";
char var;

for(int x = 0; x < input.length(); x++)
{
var = input.charAt(x);

if(var == '0')
{
record += "0000";
}
else if (var == '1')
{
record += "0001";
}
else if (var == '2')
{
record += "0010";
}
else if (var == '3')
{
record += "0011";
}
else if (var == '4')
{
record += "0100";
}
else if (var == '5')
{
record += "0101";
}
else if (var == '6')
{
record += "0110";
}
else if (var == '7')
{
record += "0111";
}
else if (var == '8')
{
record += "1000";
}
else if (var == '9')
{
record += "1001";
}
else if (var == 'A')
{
record += "1010";
}
else if (var == 'B')
{
record += "1011";
}
else if (var == 'C')
{
record += "1100";
}
else if (var == 'D')
{
record += "1101";
}
else if (var == 'E')
{
record += "1110";
}
else if (var == 'F')
{
record += "1111";
}
else
{
System.out.print("Sorry, the error is .out of range");
}
}
System.out.println(record);
return record;
}

public static long fromBiToDec(String bi)
{
long decimal = 0;

for(int y = 0; y < bi.length(); y++)
{
if(bi.charAt(y) == '1')
{
decimal = (long) (decimal + Math.pow(2, bi.length() - 1 - y));
}
}
System.out.println(decimal);
return (long) decimal;
}

public static String errorRamRangeWeb(long decimal)
{
String chipRangeFall = "";

long errorRamRange0 = 0;

long errorRamRange1 = 8589934584L;

long errorRamRange2 = 8589934585L;

long errorRamRange3 = 1717986184L;

long errorRamRange4 = 17179869185L;

long errorRamRange5 = 25769803768L;

long errorRamRange6 = 25769803769L;

long errorRamRange7 = 34359738368L;

long result = decimal;

if((result >= errorRamRange0) && (result <= errorRamRange1))
{
chipRangeFall = "1";
}
else if ((result >= errorRamRange2) && (result <= errorRamRange5))
{
chipRangeFall = "2";
}
else if ((result >= errorRamRange4) && (result <= errorRamRange3))
{
chipRangeFall = "3";
}
else if ((result >= errorRamRange6) && (result <= errorRamRange7))
{
chipRangeFall = "4";
}
else
{
System.out.println("ram chip does not exist");
}
return chipRangeFall;

}


public static void main(String[] args) throws IOException
{
readFile(convertFile);
readingLine(convertFile);
}

}

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