比较任意6个数,按从小到大的顺序输出的java语言
若以下回答无法解决问题,邀请你更新回答
1个回答
2016-05-11 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
Integer arryNum[];
int count = 0;/* 统计数字 */
boolean judgeIsNum = true;
StringBuffer stringbuffer = new StringBuffer();
Scanner scanner = new Scanner(System.in);
String character;
int memoryNum;
/**
* 任意输入字符
*
* @return 返回输入的内容
*/
// public String inputNum() {
// return null;
// }
/**
* 判断为数字
*/
public void judgmentFigures() {
while (judgeIsNum) {
System.out.println("请任意输入数字,以空格间隔,以回车结束!");
character = scanner.nextLine();
char[] figures = character.toCharArray();
for (int i = 0; i < figures.length; i++) {
if (!(figures[i] >= '1' && figures[i] <= '9')
&& figures[i] != 32) {
judgeIsNum = true;
break;
}
judgeIsNum = false;
}
if (!judgeIsNum)
stringbuffer.append(character);
}
String inputContent = stringbuffer.toString();
String[] numbers = inputContent.split("\\s+");
arryNum = new Integer[numbers.length];
for (int i = 0; i < numbers.length; i++) {
try {
memoryNum = Integer.parseInt(numbers[i]);
arryNum[count] = new Integer(memoryNum).intValue();
count++;
} catch (Exception e) {
/* 如果不出现异常,则说明肯定是数字 */
}
}
}
/**
* 对数字进行排序
*/
public void compareNum() {
for (int i = 0; i < arryNum.length; i++) {
for (int j = 0; j < arryNum.length - i - 1; j++) {
if (arryNum[j] > arryNum[j + 1]) {
Integer temp = arryNum[j];
arryNum[j] = arryNum[j + 1];
arryNum[j + 1] = temp;
}
}
}
}
/**
* 按升序排列输出
*/
public void outputNum() {
System.out.println("按升序排序:");
for (int i = 0; i < arryNum.length; i++) {
System.out.println(arryNum[i]);
}
}
}
//package com.color.program;
public class JJArrangedNumbers {
public static void main(String args[]) {
ArrangedNumbers arrangeNumbers = new ArrangedNumbers();
arrangeNumbers.judgmentFigures();
arrangeNumbers.compareNum();
arrangeNumbers.outputNum();
}
}
int count = 0;/* 统计数字 */
boolean judgeIsNum = true;
StringBuffer stringbuffer = new StringBuffer();
Scanner scanner = new Scanner(System.in);
String character;
int memoryNum;
/**
* 任意输入字符
*
* @return 返回输入的内容
*/
// public String inputNum() {
// return null;
// }
/**
* 判断为数字
*/
public void judgmentFigures() {
while (judgeIsNum) {
System.out.println("请任意输入数字,以空格间隔,以回车结束!");
character = scanner.nextLine();
char[] figures = character.toCharArray();
for (int i = 0; i < figures.length; i++) {
if (!(figures[i] >= '1' && figures[i] <= '9')
&& figures[i] != 32) {
judgeIsNum = true;
break;
}
judgeIsNum = false;
}
if (!judgeIsNum)
stringbuffer.append(character);
}
String inputContent = stringbuffer.toString();
String[] numbers = inputContent.split("\\s+");
arryNum = new Integer[numbers.length];
for (int i = 0; i < numbers.length; i++) {
try {
memoryNum = Integer.parseInt(numbers[i]);
arryNum[count] = new Integer(memoryNum).intValue();
count++;
} catch (Exception e) {
/* 如果不出现异常,则说明肯定是数字 */
}
}
}
/**
* 对数字进行排序
*/
public void compareNum() {
for (int i = 0; i < arryNum.length; i++) {
for (int j = 0; j < arryNum.length - i - 1; j++) {
if (arryNum[j] > arryNum[j + 1]) {
Integer temp = arryNum[j];
arryNum[j] = arryNum[j + 1];
arryNum[j + 1] = temp;
}
}
}
}
/**
* 按升序排列输出
*/
public void outputNum() {
System.out.println("按升序排序:");
for (int i = 0; i < arryNum.length; i++) {
System.out.println(arryNum[i]);
}
}
}
//package com.color.program;
public class JJArrangedNumbers {
public static void main(String args[]) {
ArrangedNumbers arrangeNumbers = new ArrangedNumbers();
arrangeNumbers.judgmentFigures();
arrangeNumbers.compareNum();
arrangeNumbers.outputNum();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询