gpt4 book ai didi

java - 为什么我的语句不能将字符串解析为整数?

转载 作者:行者123 更新时间:2023-12-01 04:37:46 25 4
gpt4 key购买 nike

我正在尝试将字符串解析为整数,但我得到了不兼容的类型。我的计数器用于记录文件中的记录数量,程序可以附加到文件并从中读取。现在我想对其进行排序并将其写回文件。我怎样才能执行这个任务?此处未声明的变量将在全局范围内声明。

public static void sort_addresses() throws IOException
{
String tnumber;
String tname;
String tnrooms;
int[] tmprooms;
int[] tmprooms1;
int j;
for (int i = 0; i < counter; i++)
{
for(j = 1; j < (counter-1); j++)
//while (street_name[counter] != null)
{
tmprooms = Integer.parseInt (number_rooms[counter]);
tmprooms1 = Integer.parseInt (number_rooms[counter+1]);
if (tmprooms[i] > tmprooms1[i+1])
{
tnumber = street_number[counter];
tname = street_name[counter];
tnrooms = number_rooms[counter];
street_number[counter] = street_number[counter +1];
street_name[counter] = street_name[counter+1];
number_rooms[counter] = number_rooms[counter+1];
number_rooms[counter+1] = tnumber ;
street_name[counter+1] = tname;
number_rooms[counter+1] = tnrooms;
System.out.println(street_number[i]+"\t"+street_name[i]
+"\t"+number_rooms[i]);
}
}

最佳答案

声明:

  int[] tmprooms;
int[] tmprooms1;

作为

  int tmprooms;
int tmprooms1;

Integer#parseInt()返回 int ,而不是 int[]

关于java - 为什么我的语句不能将字符串解析为整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087324/

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