【发布时间】:2016-07-22 00:06:33
【问题描述】:
我正在做这个作业,通过使用冒泡排序算法,创建一个程序,要求用户输入多个整数。
然后,程序将要求用户输入用户请求的整数,并将数组的值填充到其中。
之后,程序用户输出如下:
一个。显示文件中的号码列表(未排序) 湾。显示排序列表 C。显示最大数 d。显示最小的数字 e.显示中值 F。显示平均值
到目前为止,我有这个:
import java.util.Scanner;
public class Bubbles {
public static void main(String[] args)
{
//Declare Variables
String strUser;
int intSize;
int[] intNum;
//Input
Scanner scn=new Scanner(System.in);
//Process/Output
System.out.println("Please enter the number of values you would like to enter:");
strUser=scn.nextLine();
intSize=Integer.parseInt(strUser);
intNum=new int [intSize];
for(int i=0; i < intNum.length; i++)
{
System.out.println("Please enter for index value of "+i+":");
intNum[i]=scn.nextInt();
}
}
}
输出这个(例如):
Please enter the number of values you would like to enter: 3
Please enter for index value of 0:
47
Please enter for index value of 1:
89
Please enter for index value of 2:
42
BUILD SUCCESSFUL (total time: 13 seconds)
现在我如何将所有这些输入的数字放入一个数组中,以便我可以将它们放在一个列表中,然后使用冒泡排序对它们进行排序,等等..
像这样:
Unsorted order:
47,89,42
Sorted order:
42, 47, 89
我很迷茫,我知道。
【问题讨论】:
-
如果你对你的作业有任何疑问,你应该去找你的助教或教授。
-
欢迎来到 SO!由于您可能是新用户,我想说您确实在问一个有效的问题(至少对我而言),您提供了描述、预期的行为和到目前为止的工作(代码)。不要对投票的数量感到沮丧,人们有时只是对一个类似作业的问题投反对票,而不用想太多。不过给你一个小建议:检查你自己的问题,尝试清理你的代码格式,糟糕的代码格式更有可能导致你投很多票:)
-
我投票决定将此问题作为题外话结束,因为questions asking for homework help must include a summary of the work done so far to solve the problem, and a description of the difficulty solving it。 “到目前为止完成的工作”是指您尝试实际编写 bobblesort 代码。
-
另外,你的话题让别人很困惑,你在发问题之前应该下定决心:你问Java中如何使用数组(ArrayList)?还是您在询问冒泡排序本身的细节/算法?如果您想同时问两个问题,请分开提问,不要混淆:)
-
我很抱歉造成负面反应——这不是我的本意。但是,我理解有些人可能会认为这是“懒惰”。但我只是在努力学习。看到我在计算机编程/科学等方面的经验几乎为零,但是我想主动学习,特别是看看计算机如何成为当今社会不可或缺的一部分。不幸的是,我才上高中,我 7 月份要上的课程是基础在线课程。
标签: java arrays algorithm sorting