import java.net.*;
import java.io.*;
import java.util.Scanner;
public class Rand
{
public static void main(String[] args) throws Exception
{
System.out.printf("Integer Generator\n(c) First Name Last Name, 2014 All Rights Reserved\nNumbers Supplied by https://www.random.org/, This Connection is SSL protected by COMODO.\nGenerated numbers will be stored in output.txt\nWrite the quantities: \n");
Scanner in=new Scanner(System.in);
int p=in.nextInt(), m, n;
while(true)
{
System.out.println("Write the Maximum number: ");
m=in.nextInt();
System.out.println("Write the Minimum number: ");
n=in.nextInt();
if(n<m) break;
System.out.println("Maximum is smaller than Minimum, Try again.");
}
PrintWriter writer=new PrintWriter("output.txt");
String[] inputLine=new String[p];
boolean b=false;
int i=0;
while(i<p)
{
b=false;
HttpURLConnection c=(HttpURLConnection)new URL("https://www.random.org/integers/?num=1&min="+n+"&max="+m+"&col=1&base=10&format=plain&rnd=new").openConnection();
c.setRequestProperty("Accept-Charset", "UTF-8");
c.setDoInput(true);
c.setDoOutput(false);
c.connect();
BufferedReader out=new BufferedReader(new InputStreamReader(c.getInputStream()));
inputLine[i]=out.readLine();
c.disconnect();
for(int j=i-1; j>=0; j--)
{
if(i==0) break;
if(inputLine[j]==inputLine[i])
{
inputLine[i]=null;
b=true;
break;
}
}
if(b) continue;
writer.println(inputLine[i]);
i++;
}
writer.close();
}
}
我将此代码编程为迷你初学者项目(请原谅我,如果这有一个简单的解决方案,我是七年级学生,请不要给我扣除)
我让它随机给出一系列数字而没有相同的数字重复。
离) 1 3 五 6 4 2 如果数量为6,则最大值为6,最小值为1.
然而,它是这样的: 4 1 6 4 4 1
这有什么问题?请给我一个解释。