[英]Use sort method and JOptionPane to have user input 10 numbers and output be the 10 numbers sorted
This is what I have so far: 这是我到目前为止的内容:
import javax.swing.JOptionPane; 导入javax.swing.JOptionPane; public class Aukeemhw3 {
公共课程Aukeemhw3 {
/**
*
* @param numberSort the purpose is to sort 10 input numbers
*/
public static void numInputSort(int[] numberSort){
for(int i = 0; i < (numberSort.length - 1); i++){
int min = i;
for(int j = i; j < (numberSort.length); j++){
if(numberSort[j] < numberSort[min])
min = j;
}
int temp = numberSort[min];
numberSort[min] = numberSort[i];
numberSort[i] = temp;
}
}
/*
* @param args the command line arguments
*/
public static void main(String[] args) {
// Request for user to enter 10 numbers
String[] numbers;
numbers = new String[10];
JOptionPane.showInputDialog("Enter " + numbers + "Values: ");
numImportSort(int[] numbers);
}
} }
I keep getting errors with everything I try when calling my method at the last line. 在最后一行调用我的方法时,我尝试执行的所有操作始终出错。 I can't figure out how to properly code my main argument to ask the user to input 10 numbers then call my sort method numInputSort to sort the 10 numbers being input.
我无法弄清楚如何正确编码我的主要参数来要求用户输入10个数字,然后调用我的排序方法numInputSort来对输入的10个数字进行排序。
Plenty of errors in the main method. 主要方法中存在大量错误。 What you should do to fix:
您应该做什么来解决:
Something like 就像是
public static void main(String[] args) {
// Request for user to enter 10 numbers
int[] numbers = new int[10];
String sNumbers = JOptionPane.showInputDialog("Enter number values, split with comma: ");
String[] singleNumbers = sNumbers.split(",");
for (int i = 0; i < singleNumbers.length; i++) {
numbers[i] = Integer.parseInt(singleNumbers[i].trim());
}
numInputSort(numbers);
JOptionPane.showMessageDialog(null, Arrays.toString(numbers), "sorted", JOptionPane.INFORMATION_MESSAGE);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.