java 打乱 数字_如何在JAVA中随机打乱输出一组数字而不重复

问题是要求用户输入两个不同的数字,然后JAVA随即打乱输出包含在这两个数之间的所有整数,然后计算最大和第二大的数字中间夹着的数字和。例子:Enteranumber:6Enteranumber:-35,4,0,-2...

问题是 要求用户输入两个不同的数字,然后JAVA随即打乱输出包含在这两个数之间的所有整数,然后计算最大和第二大的数字中间夹着的数字和。例子:

Enter a number: 6

Enter a number: -3

5,4,0,-2,1,-3,6,-1,3,2

Largest pair sum: 9

输入数字的一部分我已经完成,剩下的部分实在有点不会....求各位大大指教!!

附上已完成的部分= =

import java.io.*;

import java.util.Random;

public class A6{

public static void main(String[] args) throws IOException {

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

boolean same = false;

int num1 = 0;

int num2 = 0;

while (!same) {//if the numbers which user enter are the same,do it again

try {

System.out.print("enter a number: ");//ask user a number

num1 = Integer.parseInt(in.readLine());

System.out.print("enter another number: ");//ask user another number

num2 = Integer.parseInt(in.readLine());

if (num1 != num2) {

same = true;//if the number are different,continue the next part and don't need to enter again

} else {

System.out.println("two numbers is same.");//if not , ask user enter again

}

} catch (NumberFormatException nfc) {//text the enter is a number or not,if not,ask user enter again

System.out.println("not a number");//show user the reason why get false

}

}

最后一个要求错了.....应该是找出相加结果最大的相邻的两个数字,然后把结果打印出来

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值