java 整数数组排序_java-使用字符串和数组中的int排序

我的作业要求我制作一个电视节目,我可以在其中输入节目,删除,修改和排序节目.我坚持的是排序部分.该程序会提示用户输入节目名称,新剧集首播的日期和时间,这些都存储在数组中.它按键名称,日期和时间(字母和数字)排序.

该程序提示用户输入这些键之一,然后该程序需要按该键对显示进行排序(按天排序将按字母顺序排序).

我制作了一个类,并使用数组保存了输入的节目.这是课程:

public class showInfo

{

String name;

String day;

int time;

}

我已经输入了这样的节目:

public static void addShow() throws IOException

{

//initialize counter

int i = 0;

arr = new showInfo[i];

showInfo temp = new showInfo();

//input information

do

{

System.out.print("Enter the name of show: ");

String showName = br.readLine();

temp.name = showName;

System.out.print("Enter which day of the week a new episode premieres: ");

String showDay = br.readLine();

temp.day = showDay;

System.out.print("Enter time in 24-hour format (e.g. 2100, 1900): ");

int showTime = Integer.valueOf(br.readLine()).intValue();

temp.time = showTime;

i++;

System.out.print("Would you like to add another show? (y/n) ");

}

while((br.readLine().compareTo("n"))!=0);

}

为了按时间排序,我编写了以下方法:

public static void timeSort()

{

int min;

for (int i = 0; i < arr.length; i++)

{

// Assume first element is min

min = i;

for (int j = i+1; j < arr.length; j++)

{

if (arr[j].time < arr[min].time)

{

min = j;

}

}

if (min != i)

{

int temp = arr[i].time;

arr[i].time = arr[min].time;

arr[min].time = temp;

}

}

System.out.println("TV Shows by Time");

for(int i = 0; i < arr.length; i++)

{

System.out.println(arr[i].name + " - " + arr[i].day + " - " + arr[i].time + " hours");

}

}

我的问题是,当我调用它并在主机中输出它时,它仅显示“按时间显示电视节目”文本,而不显示节目.为什么是这样? (我应该显示完整的代码吗?)

我认为我的问题与计数器有关,但是我不确定该如何解决,因为用户应该输入所需的任意数量的节目,并且其他节目的显示数量被修改和删除方法.

任何帮助将是巨大的!提前致谢!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值