Netbeans 在if语句中发出,以便在java程序中进行比较

Netbeans 在if语句中发出,以便在java程序中进行比较,netbeans,random,bubble-sort,Netbeans,Random,Bubble Sort,请帮忙,我已经写了程序,但是for循环中的if语句不起作用。程序需要生成6个随机数,然后应用我已经做过的冒泡排序。然后用户必须输入6个数字,这些数字必须与随机数进行比较,并且必须说明是否在随机数中找到数字。这是密码。if语句'publicstaticvoidmain(String[]args)有问题{ 试一试{ int numbers[] = new int[6]; //random numbers will be stored in new array //2

请帮忙,我已经写了程序,但是for循环中的if语句不起作用。程序需要生成6个随机数,然后应用我已经做过的冒泡排序。然后用户必须输入6个数字,这些数字必须与随机数进行比较,并且必须说明是否在随机数中找到数字。这是密码。if语句'publicstaticvoidmain(String[]args)有问题{ 试一试{

        int numbers[] = new int[6];  //random numbers will be stored in new array
        //2 loop will be created to avoid duplication of numbers 
        System.out.println("Array before Bubble sort");
        for (int i = 0; i < 6; i++) {
            numbers[i] = (int) (Math.random() * 40);
            if (i > 0) {
                for (int b = 0; b < i; b++) {  //
                    if (numbers[b] == numbers[i]) {
                        i--;  //decrement to continue the for loop if the integer has been repeated
                    }
                }
            }

            System.out.print(numbers[i] + ",");  //random numbers will be printed before using sorting bubble sort

        }
        //sort an array using bubble sort
        bubbleSort(numbers);
        System.out.println("    \nArray after bubble sort");
        for (int i = 0; i < 6; i++) {
            System.out.print(numbers[i] + ",");
        }
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

        System.out.println("\ninput 6 number between 1 and 40");
        int inputNumber = Integer.parseInt(input.readLine());
        for (int b = 0; b < 6; b++) {
            System.out.println("number:");
            int outcome=Integer.parseInt(input.readLine());
            if(outcome==numbers){
                System.out.println("found in random numbers");
            }else{
                System.out.println("not found in random numbers");
            }
        }

    } catch (Exception e) {
        System.out.println("error");
    }

}

public static void bubbleSort(int[] numbers) {

    int n = numbers.length;
    int temp = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < (n - i); j++) {
            if (numbers[j - 1] > numbers[j]) {  //swap the element
                temp = numbers[j - 1];
                numbers[j - 1] = numbers[j];
                numbers[j] = temp;

            }
        }
    }

}
int numbers[]=new int[6];//随机数将存储在新数组中
//将创建2个循环,以避免重复编号
System.out.println(“气泡排序前的数组”);
对于(int i=0;i<6;i++){
数字[i]=(int)(Math.random()*40);
如果(i>0){
对于(intb=0;bnumbers[j]){//交换元素
温度=数字[j-1];
数字[j-1]=数字[j];
数字[j]=温度;
}
}
}
}
}`

System.out.println(“\n输入1到40之间的6个数字”);
//Scanner是专门为获取输入目的而设计的,并在Java5中引入,因此更好地使用它
扫描仪s=新的扫描仪(System.in);
//这里需要嵌套循环
//但是最好的搜索方法是使用二进制搜索,因为您已经对数组进行了排序
而(s.hasnetint()){
//从输入到结果,一次一个
int-outcome=s.nextInt();
布尔值=false;
对于(int b=0;b<6;b++){
发现=错误;
如果(结果==数字[b]){
发现=真;
//如果找到匹配项,请记住中断内部循环
打破
}否则{
发现=错误;
}
}
if(find==true){
System.out.println(“在随机数中找到”);
}否则{
System.out.println(“未在随机数中找到”);
}

在将数组设置为随机数的for循环中,在添加到数组之前,需要检查该数字是否存在。
System.out.println("\ninput 6 number between 1 and 40");
        //Scanner is specifically designed for getting an input purpose and introduced in Java 5,so better use it
        Scanner s = new Scanner(System.in);

        //you need to have nested loop here
        //But the best way to search is use binary search,as you have already sorted the array
        while (s.hasNextInt()) {
            //one at a time from the input is put to outcome
            int outcome = s.nextInt();
            boolean found = false;

            for (int b = 0; b < 6; b++) {


                found = false;

                if (outcome == numbers[b]) {
                    found = true;
                    //remember to break the inner loop if a match is found
                    break;
                } else {

                    found = false;
                }

            }
            if (found == true) {
                System.out.println("found in random numbers");
            } else {
                System.out.println("not found in random numbers");
            }